on master help sign in
Inline splitAt in MutArray and Array modules
894fd29Harendra Kumar
core/src/Streamly/Internal/Data/Array/Type.hs+2−1
@@ -48,6 +48,7 @@ module Streamly.Internal.Data.Array.Type
48
48
49 -- ** Split
49 -- ** Split
50 , breakOn
50 , breakOn
51+ , splitAt
51
52
52 -- ** Cloning arrays
53 -- ** Cloning arrays
53 , clone
54 , clone
@@ -61,7 +62,6 @@ module Streamly.Internal.Data.Array.Type
61
62
62 , foldl'
63 , foldl'
63 , foldr
64 , foldr
64− , splitAt
65
65
66 , toStreamK
66 , toStreamK
67 , toStreamKRev
67 , toStreamKRev
@@ -559,6 +559,7 @@ foldr f z arr = runIdentity $ D.foldr f z $ toStreamD arr
559-- | Create two slices of an array without copying the original array. The
559-- | Create two slices of an array without copying the original array. The
560-- specified index @i@ is the first index of the second slice.
560-- specified index @i@ is the first index of the second slice.
561--
561--
562+{-# INLINE splitAt #-}
562splitAt :: Unbox a => Int -> Array a -> (Array a, Array a)
563splitAt :: Unbox a => Int -> Array a -> (Array a, Array a)
563splitAt i arr = (unsafeFreeze a, unsafeFreeze b)
564splitAt i arr = (unsafeFreeze a, unsafeFreeze b)
564 where
565 where
core/src/Streamly/Internal/Data/MutArray/Type.hs+1
@@ -2423,6 +2423,7 @@ breakOn sep arr@MutArray{..} = asUnpinnedPtrUnsafe arr $ \p -> liftIO $ do
2423-- | Create two slices of an array without copying the original array. The
2423-- | Create two slices of an array without copying the original array. The
2424-- specified index @i@ is the first index of the second slice.
2424-- specified index @i@ is the first index of the second slice.
2425--
2425--
2426+{-# INLINE splitAt #-}
2426splitAt :: forall a. Unbox a => Int -> MutArray a -> (MutArray a, MutArray a)
2427splitAt :: forall a. Unbox a => Int -> MutArray a -> (MutArray a, MutArray a)
2427splitAt i arr@MutArray{..} =
2428splitAt i arr@MutArray{..} =
2428 let maxIndex = length arr - 1
2429 let maxIndex = length arr - 1