on master help sign in
Rename unsafeIndex and unsafeWriteIndex

To getIndexUnsafe and putIndexUnsafe.

commit0d6a0aa9438d07afa0dfaf670b29719f4d23ea2e authorHarendra Kumar <harendra@composewell.com> dateSun 10 Oct 2021, 20:03 (5 years ago) parentfff2704
3 files changed+11−11
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+8−8 src/Streamly/Internal/Data/Array/Foreign/Type.hs+1−1 test/Streamly/Test/Common/Array.hs+2−2
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+8−8
@@ -37,10 +37,10 @@ module Streamly.Internal.Data.Array.Foreign.Mut.Type
3737 , byteCapacity
3838
3939 -- * Random access
40− , unsafeIndex
40+ , getIndexUnsafe
4141
4242 -- * Mutation
43− , unsafeWriteIndex
43+ , putIndexUnsafe
4444 , snocUnsafe
4545 , snoc
4646
@@ -317,10 +317,10 @@ unsafeWithNewArray count f = do
317317-- Mutation
318318-------------------------------------------------------------------------------
319319
320−{-# INLINE unsafeWriteIndex #-}
321−unsafeWriteIndex :: forall m a. (MonadIO m, Storable a)
320+{-# INLINE putIndexUnsafe #-}
321+putIndexUnsafe :: forall m a. (MonadIO m, Storable a)
322322 => Array a -> Int -> a -> m ()
323−unsafeWriteIndex Array {..} i x =
323+putIndexUnsafe Array {..} i x =
324324 unsafeWithForeignPtrM aStart
325325 $ \begin -> do
326326 liftIO $ poke (begin `plusPtr` (i * sizeOf (undefined :: a))) x
@@ -418,9 +418,9 @@ shrinkToFit arr@Array{..} = do
418418-- | Return the element at the specified index without checking the bounds.
419419--
420420-- Unsafe because it does not check the bounds of the array.
421−{-# INLINE_NORMAL unsafeIndex #-}
422−unsafeIndex :: forall m a. (MonadIO m, Storable a) => Array a -> Int -> m a
423−unsafeIndex Array {..} i =
421+{-# INLINE_NORMAL getIndexUnsafe #-}
422+getIndexUnsafe :: forall m a. (MonadIO m, Storable a) => Array a -> Int -> m a
423+getIndexUnsafe Array {..} i =
424424 unsafeWithForeignPtrM aStart $ \p -> do
425425 let elemSize = sizeOf (undefined :: a)
426426 elemOff = p `plusPtr` (elemSize * i)
src/Streamly/Internal/Data/Array/Foreign/Type.hs+1−1
@@ -407,7 +407,7 @@ breakOn sep arr = do
407407-- Unsafe because it does not check the bounds of the array.
408408{-# INLINE_NORMAL unsafeIndexIO #-}
409409unsafeIndexIO :: forall a. Storable a => Array a -> Int -> IO a
410−unsafeIndexIO arr = MA.unsafeIndex (unsafeThaw arr)
410+unsafeIndexIO arr = MA.getIndexUnsafe (unsafeThaw arr)
411411
412412-- | Return element at the specified index without checking the bounds.
413413{-# INLINE_NORMAL unsafeIndex #-}
test/Streamly/Test/Common/Array.hs+2−2
@@ -195,8 +195,8 @@ foldManyWith f =
195195unsafeWriteIndex :: [Int] -> Int -> Int -> IO Bool
196196unsafeWriteIndex xs i x = do
197197 arr <- MA.fromList xs
198− MA.unsafeWriteIndex arr i x
199− x1 <- MA.unsafeIndex arr i
198+ MA.putIndexUnsafe arr i x
199+ x1 <- MA.getIndexUnsafe arr i
200200 return $ x1 == x
201201
202202lastN :: Int -> [a] -> [a]