@@ -869,7 +869,7 @@ writeChunks = undefined -- Fold.many Fold.toStream (Array.writeN n)
869869-- XXX The realloc based implementation needs to make one extra copy if we use
870870-- shrinkToFit. On the other hand, the stream of arrays implementation may
871871-- buffer the array chunk pointers in memory but it does not have to shrink as
872−-- we know the exact size in the end. However, memory copying does not seems to
872+-- we know the exact size in the end. However, memory copying does not seem to
873873-- be as expensive as the allocations. Therefore, we need to reduce the number
874874-- of allocations instead. Also, the size of allocations matters, right sizing
875875-- an allocation even at the cost of copying sems to help. Should be measured
@@ -894,7 +894,8 @@ toArrayMinChunk alignSize elemCount =
894894 initial = do
895895 when (elemCount < 0) $ error "toArrayMinChunk: elemCount is negative"
896896 liftIO $ newArrayAligned alignSize elemCount
897− step arr@(Array start end bound) x | end == bound = do
897+ step arr@(Array start end bound) x
898+ | end `plusPtr` sizeOf (undefined :: a) > bound = do
898899 let p = unsafeForeignPtrToPtr start
899900 oldSize = end `minusPtr` p
900901 newSize = max (oldSize * 2) 1