on master help sign in
Simplify writeWith
commitc1f20bf462d2f17f651555f1cc08c1a89dd1ba82 authorHarendra Kumar <harendra@composewell.com> dateFri 10 Mar 2023, 12:56 (4 years ago) parent0d157cc
1 file changed+4−6
core/src/Streamly/Internal/Data/Array/Mut/Type.hs+4−6
core/src/Streamly/Internal/Data/Array/Mut/Type.hs+4−6
@@ -1880,20 +1880,18 @@ writeWith elemCount =
18801880
18811881 where
18821882
1883− insertElem (MutArray contents start end bound) x = do
1884− liftIO $ pokeWith contents end x
1885− return $ MutArray contents start (INDEX_NEXT(end,a)) bound
1886−
18871883 initial = do
18881884 when (elemCount < 0) $ error "writeWith: elemCount is negative"
18891885 liftIO $ newPinned elemCount
1886+
18901887 step arr@(MutArray _ start end bound) x
18911888 | INDEX_NEXT(end,a) > bound = do
18921889 let oldSize = end - start
18931890 newSize = max (oldSize * 2) 1
18941891 arr1 <- liftIO $ reallocExplicit (SIZE_OF(a)) newSize arr
1895− insertElem arr1 x
1896− step arr x = insertElem arr x
1892+ snocUnsafe arr1 x
1893+ step arr x = snocUnsafe arr x
1894+
18971895 extract = liftIO . rightSize
18981896
18991897-- | Fold the whole input to a single array.