boost performance by replacing array_merge with foreach-loops