on master help sign in
Rename unsafeIndex and unsafeWriteIndex
0d6a0aaHarendra Kumar
src/Streamly/Internal/Data/Array/Foreign/Mut/Type.hs+8−8
@@ -37,10 +37,10 @@ module Streamly.Internal.Data.Array.Foreign.Mut.Type
37 , byteCapacity
37 , byteCapacity
38
38
39 -- * Random access
39 -- * Random access
40− , unsafeIndex
40+ , getIndexUnsafe
41
41
42 -- * Mutation
42 -- * Mutation
43− , unsafeWriteIndex
43+ , putIndexUnsafe
44 , snocUnsafe
44 , snocUnsafe
45 , snoc
45 , snoc
46
46
@@ -317,10 +317,10 @@ unsafeWithNewArray count f = do
317-- Mutation
317-- Mutation
318-------------------------------------------------------------------------------
318-------------------------------------------------------------------------------
319
319
320−{-# INLINE unsafeWriteIndex #-}
320+{-# INLINE putIndexUnsafe #-}
321−unsafeWriteIndex :: forall m a. (MonadIO m, Storable a)
321+putIndexUnsafe :: forall m a. (MonadIO m, Storable a)
322 => Array a -> Int -> a -> m ()
322 => Array a -> Int -> a -> m ()
323−unsafeWriteIndex Array {..} i x =
323+putIndexUnsafe Array {..} i x =
324 unsafeWithForeignPtrM aStart
324 unsafeWithForeignPtrM aStart
325 $ \begin -> do
325 $ \begin -> do
326 liftIO $ poke (begin `plusPtr` (i * sizeOf (undefined :: a))) x
326 liftIO $ poke (begin `plusPtr` (i * sizeOf (undefined :: a))) x
@@ -418,9 +418,9 @@ shrinkToFit arr@Array{..} = do
418-- | Return the element at the specified index without checking the bounds.
418-- | Return the element at the specified index without checking the bounds.
419--
419--
420-- Unsafe because it does not check the bounds of the array.
420-- Unsafe because it does not check the bounds of the array.
421−{-# INLINE_NORMAL unsafeIndex #-}
421+{-# INLINE_NORMAL getIndexUnsafe #-}
422−unsafeIndex :: forall m a. (MonadIO m, Storable a) => Array a -> Int -> m a
422+getIndexUnsafe :: forall m a. (MonadIO m, Storable a) => Array a -> Int -> m a
423−unsafeIndex Array {..} i =
423+getIndexUnsafe Array {..} i =
424 unsafeWithForeignPtrM aStart $ \p -> do
424 unsafeWithForeignPtrM aStart $ \p -> do
425 let elemSize = sizeOf (undefined :: a)
425 let elemSize = sizeOf (undefined :: a)
426 elemOff = p `plusPtr` (elemSize * i)
426 elemOff = p `plusPtr` (elemSize * i)
src/Streamly/Internal/Data/Array/Foreign/Type.hs+1−1
@@ -407,7 +407,7 @@ breakOn sep arr = do
407-- Unsafe because it does not check the bounds of the array.
407-- Unsafe because it does not check the bounds of the array.
408{-# INLINE_NORMAL unsafeIndexIO #-}
408{-# INLINE_NORMAL unsafeIndexIO #-}
409unsafeIndexIO :: forall a. Storable a => Array a -> Int -> IO a
409unsafeIndexIO :: forall a. Storable a => Array a -> Int -> IO a
410−unsafeIndexIO arr = MA.unsafeIndex (unsafeThaw arr)
410+unsafeIndexIO arr = MA.getIndexUnsafe (unsafeThaw arr)
411
411
412-- | Return element at the specified index without checking the bounds.
412-- | Return element at the specified index without checking the bounds.
413{-# INLINE_NORMAL unsafeIndex #-}
413{-# INLINE_NORMAL unsafeIndex #-}
test/Streamly/Test/Common/Array.hs+2−2
@@ -195,8 +195,8 @@ foldManyWith f =
195unsafeWriteIndex :: [Int] -> Int -> Int -> IO Bool
195unsafeWriteIndex :: [Int] -> Int -> Int -> IO Bool
196unsafeWriteIndex xs i x = do
196unsafeWriteIndex xs i x = do
197 arr <- MA.fromList xs
197 arr <- MA.fromList xs
198− MA.unsafeWriteIndex arr i x
198+ MA.putIndexUnsafe arr i x
199− x1 <- MA.unsafeIndex arr i
199+ x1 <- MA.getIndexUnsafe arr i
200 return $ x1 == x
200 return $ x1 == x
201
201
202lastN :: Int -> [a] -> [a]
202lastN :: Int -> [a] -> [a]