on master help sign in
Rename unsafeSlice to getSliceUnsafe
2094338Harendra Kumar
src/Streamly/Internal/Data/Array/Foreign.hs+7−6
@@ -102,7 +102,7 @@ module Streamly.Internal.Data.Array.Foreign
102 , A.unsafeThaw -- asMutableUnsafe?
102 , A.unsafeThaw -- asMutableUnsafe?
103
103
104 -- * Subarrays
104 -- * Subarrays
105− , unsafeSlice
105+ , getSliceUnsafe
106 -- , getSlice
106 -- , getSlice
107 -- , getSlicesFromLenN
107 -- , getSlicesFromLenN
108
108
@@ -115,6 +115,7 @@ module Streamly.Internal.Data.Array.Foreign
115 )
115 )
116where
116where
117
117
118+import Control.Exception (assert)
118import Control.Monad (when)
119import Control.Monad (when)
119import Control.Monad.IO.Class (MonadIO(..))
120import Control.Monad.IO.Class (MonadIO(..))
120import Data.Functor.Identity (Identity)
121import Data.Functor.Identity (Identity)
@@ -361,18 +362,18 @@ find = Unfold.fold Fold.null . Stream.unfold (findIndicesOf p)
361-- /Unsafe/
362-- /Unsafe/
362--
363--
363-- /Pre-release/
364-- /Pre-release/
364−{-# INLINE unsafeSlice #-}
365+{-# INLINE getSliceUnsafe #-}
365−unsafeSlice ::
366+getSliceUnsafe ::
366 forall a. Storable a
367 forall a. Storable a
367 => Int -- ^ starting index
368 => Int -- ^ starting index
368 -> Int -- ^ length of the slice
369 -> Int -- ^ length of the slice
369 -> Array a
370 -> Array a
370 -> Array a
371 -> Array a
371−unsafeSlice start len (Array fp _) =
372+getSliceUnsafe index len (Array fp e) =
372 let size = sizeOf (undefined :: a)
373 let size = sizeOf (undefined :: a)
373− fp1 = fp `plusForeignPtr` (start * size)
374+ fp1 = fp `plusForeignPtr` (index * size)
374 end = unsafeForeignPtrToPtr fp1 `plusPtr` (len * size)
375 end = unsafeForeignPtrToPtr fp1 `plusPtr` (len * size)
375− in Array fp1 end
376+ in assert (end <= e) (Array fp1 end)
376
377
377-------------------------------------------------------------------------------
378-------------------------------------------------------------------------------
378-- Random reads and writes
379-- Random reads and writes
test/Streamly/Test/Common/Array.hs+1−1
@@ -234,7 +234,7 @@ concatArrayW8 =
234unsafeSlice :: Int -> Int -> [Int] -> Bool
234unsafeSlice :: Int -> Int -> [Int] -> Bool
235unsafeSlice i n list =
235unsafeSlice i n list =
236 let lst = take n $ drop i $ list
236 let lst = take n $ drop i $ list
237− arr = A.toList $ A.unsafeSlice i n $ A.fromList list
237+ arr = A.toList $ A.getSliceUnsafe i n $ A.fromList list
238 in arr == lst
238 in arr == lst
239
239
240#endif
240#endif