@@ -38,6 +38,7 @@ module Streamly.Internal.Data.Array.Generic
39 -- * Random Access
39 -- * Random Access
40 , getIndexUnsafe
40 , getIndexUnsafe
@@ -217,9 +218,9 @@ writeLastN n = FL.rmapM f (RB.writeLastN n)
217 arr <- RB.toMutArray 0 n rb
218 arr <- RB.toMutArray 0 n rb
218 return $ unsafeFreeze arr
219 return $ unsafeFreeze arr
220−{-# INLINE sliceUnsafe #-}
221+{-# INLINE getSliceUnsafe #-}
221−sliceUnsafe :: Int -> Int -> Array a -> Array a
222+getSliceUnsafe :: Int -> Int -> Array a -> Array a
222−sliceUnsafe offset len (Array cont off1 _) = Array cont (off1 + offset) len
223+getSliceUnsafe offset len (Array cont off1 _) = Array cont (off1 + offset) len
224-- XXX This is not efficient as it copies the array. We should support array
225-- XXX This is not efficient as it copies the array. We should support array
225-- slicing so that we can just refer to the underlying array memory instead of
226-- slicing so that we can just refer to the underlying array memory instead of
@@ -229,32 +230,7 @@ sliceUnsafe offset len (Array cont off1 _) = Array cont (off1 + offset) len
229-- holds true. Returns a slice of the original array.
230-- holds true. Returns a slice of the original array.
230{-# INLINE strip #-}
231{-# INLINE strip #-}
231strip :: (a -> Bool) -> Array a -> Array a
232strip :: (a -> Bool) -> Array a -> Array a
232−strip p arr =
233+strip p arr = unsafeFreeze $ unsafePerformIO $ MArray.strip p (unsafeThaw arr)
233− let lastIndex = length arr - 1
234− indexR = getIndexR lastIndex -- last predicate failing index
238− let indexL = getIndexL 0 -- first predicate failing index
239− in if indexL == 0 && indexR == lastIndex
242− let newLen = indexR - indexL + 1
243− in sliceUnsafe indexL newLen arr
250− if p (getIndexUnsafe idx arr)
251− then getIndexR (idx - 1)
255− if p (getIndexUnsafe idx arr)
256− then getIndexL (idx + 1)
259-------------------------------------------------------------------------------
235-------------------------------------------------------------------------------
260-- Instances
236-- Instances