on master help sign in
Rename unsafeSlice to getSliceUnsafe
commit209433807fcf991bbf5bb6e258aabe2dc6911327 authorHarendra Kumar <harendra@composewell.com> dateWed 6 Oct 2021, 10:46 (5 years ago) parent58051d0
2 files changed+8−7
src/Streamly/Internal/Data/Array/Foreign.hs+7−6 test/Streamly/Test/Common/Array.hs+1−1
src/Streamly/Internal/Data/Array/Foreign.hs+7−6
@@ -102,7 +102,7 @@ module Streamly.Internal.Data.Array.Foreign
102102 , A.unsafeThaw -- asMutableUnsafe?
103103
104104 -- * Subarrays
105− , unsafeSlice
105+ , getSliceUnsafe
106106 -- , getSlice
107107 -- , getSlicesFromLenN
108108
@@ -115,6 +115,7 @@ module Streamly.Internal.Data.Array.Foreign
115115 )
116116where
117117
118+import Control.Exception (assert)
118119import Control.Monad (when)
119120import Control.Monad.IO.Class (MonadIO(..))
120121import Data.Functor.Identity (Identity)
@@ -361,18 +362,18 @@ find = Unfold.fold Fold.null . Stream.unfold (findIndicesOf p)
361362-- /Unsafe/
362363--
363364-- /Pre-release/
364−{-# INLINE unsafeSlice #-}
365−unsafeSlice ::
365+{-# INLINE getSliceUnsafe #-}
366+getSliceUnsafe ::
366367 forall a. Storable a
367368 => Int -- ^ starting index
368369 -> Int -- ^ length of the slice
369370 -> Array a
370371 -> Array a
371−unsafeSlice start len (Array fp _) =
372+getSliceUnsafe index len (Array fp e) =
372373 let size = sizeOf (undefined :: a)
373− fp1 = fp `plusForeignPtr` (start * size)
374+ fp1 = fp `plusForeignPtr` (index * size)
374375 end = unsafeForeignPtrToPtr fp1 `plusPtr` (len * size)
375− in Array fp1 end
376+ in assert (end <= e) (Array fp1 end)
376377
377378-------------------------------------------------------------------------------
378379-- Random reads and writes
test/Streamly/Test/Common/Array.hs+1−1
@@ -234,7 +234,7 @@ concatArrayW8 =
234234unsafeSlice :: Int -> Int -> [Int] -> Bool
235235unsafeSlice i n list =
236236 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
238238 in arr == lst
239239
240240#endif