on master help sign in
Change argument order of put/modifyIndex in Generic array
b56e0a1Harendra Kumar
core/src/Streamly/Internal/Data/Array/Generic.hs+2−2
@@ -137,7 +137,7 @@ fromStreamDN limit str = do
137 marr <- liftIO $ MArray.new (max limit 0)
137 marr <- liftIO $ MArray.new (max limit 0)
138 i <-
138 i <-
139 D.foldlM'
139 D.foldlM'
140− (\i x -> i `seq` liftIO $ MArray.putIndexUnsafe i x marr >> return (i + 1))
140+ (\i x -> i `seq` liftIO $ MArray.putIndexUnsafe i marr x >> return (i + 1))
141 (return 0) $
141 (return 0) $
142 D.take limit str
142 D.take limit str
143 return $ unsafeFreeze $ marr { MArray.arrLen = i }
143 return $ unsafeFreeze $ marr { MArray.arrLen = i }
@@ -320,7 +320,7 @@ putIndices arr = FL.rmapM (\ _ -> return ()) (FL.foldlM' step initial)
320 initial = return $ unsafeThaw arr
320 initial = return $ unsafeThaw arr
321
321
322 step marr (i, x) = do
322 step marr (i, x) = do
323− MArray.putIndexUnsafe i x marr
323+ MArray.putIndexUnsafe i marr x
324 return marr
324 return marr
325
325
326-------------------------------------------------------------------------------
326-------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/Array/Generic/Mut/Type.hs+12−12
@@ -251,8 +251,8 @@ new n@(I# n#) =
251--
251--
252-- /Pre-release/
252-- /Pre-release/
253{-# INLINE putIndexUnsafe #-}
253{-# INLINE putIndexUnsafe #-}
254−putIndexUnsafe :: forall m a. MonadIO m => Int -> a -> Array a -> m ()
254+putIndexUnsafe :: forall m a. MonadIO m => Int -> Array a -> a -> m ()
255−putIndexUnsafe i x Array {..} =
255+putIndexUnsafe i Array {..} x =
256 liftIO
256 liftIO
257 $ IO
257 $ IO
258 $ \s# ->
258 $ \s# ->
@@ -268,14 +268,14 @@ invalidIndex label i =
268-- | /O(1)/ Write the given element at the given index in the array.
268-- | /O(1)/ Write the given element at the given index in the array.
269-- Performs in-place mutation of the array.
269-- Performs in-place mutation of the array.
270--
270--
271−-- >>> putIndex ix val arr = Array.modifyIndex ix (const (val, ())) arr
271+-- >>> putIndex ix arr val = Array.modifyIndex ix arr (const (val, ()))
272--
272--
273-- /Pre-release/
273-- /Pre-release/
274{-# INLINE putIndex #-}
274{-# INLINE putIndex #-}
275−putIndex :: MonadIO m => Int -> a -> Array a -> m ()
275+putIndex :: MonadIO m => Int -> Array a -> a -> m ()
276−putIndex i x arr@Array {..} =
276+putIndex i arr@Array {..} x =
277 if i >= 0 && i < arrLen
277 if i >= 0 && i < arrLen
278− then putIndexUnsafe i x arr
278+ then putIndexUnsafe i arr x
279 else invalidIndex "putIndex" i
279 else invalidIndex "putIndex" i
280
280
281-- | Modify a given index of an array using a modifier function without checking
281-- | Modify a given index of an array using a modifier function without checking
@@ -284,8 +284,8 @@ putIndex i x arr@Array {..} =
284-- Unsafe because it does not check the bounds of the array.
284-- Unsafe because it does not check the bounds of the array.
285--
285--
286-- /Pre-release/
286-- /Pre-release/
287−modifyIndexUnsafe :: MonadIO m => Int -> (a -> (a, b)) -> Array a -> m b
287+modifyIndexUnsafe :: MonadIO m => Int -> Array a -> (a -> (a, b)) -> m b
288−modifyIndexUnsafe i f Array {..} = do
288+modifyIndexUnsafe i Array {..} f = do
289 liftIO
289 liftIO
290 $ IO
290 $ IO
291 $ \s# ->
291 $ \s# ->
@@ -300,10 +300,10 @@ modifyIndexUnsafe i f Array {..} = do
300-- | Modify a given index of an array using a modifier function.
300-- | Modify a given index of an array using a modifier function.
301--
301--
302-- /Pre-release/
302-- /Pre-release/
303−modifyIndex :: MonadIO m => Int -> (a -> (a, b)) -> Array a -> m b
303+modifyIndex :: MonadIO m => Int -> Array a -> (a -> (a, b)) -> m b
304−modifyIndex i f arr@Array {..} = do
304+modifyIndex i arr@Array {..} f = do
305 if i >= 0 && i < arrLen
305 if i >= 0 && i < arrLen
306− then modifyIndexUnsafe i f arr
306+ then modifyIndexUnsafe i arr f
307 else invalidIndex "modifyIndex" i
307 else invalidIndex "modifyIndex" i
308
308
309-------------------------------------------------------------------------------
309-------------------------------------------------------------------------------
@@ -362,7 +362,7 @@ reallocWith label sizer reqSize arr = do
362snocUnsafe :: MonadIO m => Array a -> a -> m (Array a)
362snocUnsafe :: MonadIO m => Array a -> a -> m (Array a)
363snocUnsafe arr@Array {..} a = do
363snocUnsafe arr@Array {..} a = do
364 assert (arrStart + arrLen < arrTrueLen) (return ())
364 assert (arrStart + arrLen < arrTrueLen) (return ())
365− putIndexUnsafe arrLen a arr
365+ putIndexUnsafe arrLen arr a
366 return $ arr {arrLen = arrLen + 1}
366 return $ arr {arrLen = arrLen + 1}
367
367
368-- NOINLINE to move it out of the way and not pollute the instruction cache.
368-- NOINLINE to move it out of the way and not pollute the instruction cache.
core/src/Streamly/Internal/Data/Ring.hs+1−1
@@ -40,7 +40,7 @@ createRing count = do
40{-# INLINE unsafeInsertRing #-}
40{-# INLINE unsafeInsertRing #-}
41unsafeInsertRing :: Ring a -> Int -> a -> IO ()
41unsafeInsertRing :: Ring a -> Int -> a -> IO ()
42unsafeInsertRing Ring{..} idx x = do
42unsafeInsertRing Ring{..} idx x = do
43− putIndexUnsafe (mod idx ringMax) x arr
43+ putIndexUnsafe (mod idx ringMax) arr x
44 ref <- readIORef ringHead
44 ref <- readIORef ringHead
45 if (ref+1) < ringMax
45 if (ref+1) < ringMax
46 then modifyIORef' ringHead ( + 1)
46 then modifyIORef' ringHead ( + 1)