Optimizing `array.compact()`