optimized Arrays.reduce