@@ -869,7 +869,7 @@ writeChunks = undefined -- Fold.many Fold.toStream (Array.writeN n)
869-- XXX The realloc based implementation needs to make one extra copy if we use
869-- XXX The realloc based implementation needs to make one extra copy if we use
870-- shrinkToFit. On the other hand, the stream of arrays implementation may
870-- shrinkToFit. On the other hand, the stream of arrays implementation may
871-- buffer the array chunk pointers in memory but it does not have to shrink as
871-- 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
873-- be as expensive as the allocations. Therefore, we need to reduce the number
873-- be as expensive as the allocations. Therefore, we need to reduce the number
874-- of allocations instead. Also, the size of allocations matters, right sizing
874-- of allocations instead. Also, the size of allocations matters, right sizing
875-- an allocation even at the cost of copying sems to help. Should be measured
875-- an allocation even at the cost of copying sems to help. Should be measured
@@ -894,7 +894,8 @@ toArrayMinChunk alignSize elemCount =
894 initial = do
894 initial = do
895 when (elemCount < 0) $ error "toArrayMinChunk: elemCount is negative"
895 when (elemCount < 0) $ error "toArrayMinChunk: elemCount is negative"
896 liftIO $ newArrayAligned alignSize elemCount
896 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
898 let p = unsafeForeignPtrToPtr start
899 let p = unsafeForeignPtrToPtr start
899 oldSize = end `minusPtr` p
900 oldSize = end `minusPtr` p
900 newSize = max (oldSize * 2) 1
901 newSize = max (oldSize * 2) 1