on master help sign in
Inline splitAt in MutArray and Array modules
commit894fd29906ffb46076979fa8741e5ec4399a9bea authorHarendra Kumar <harendra@composewell.com> dateSun 31 Dec 2023, 05:41 (3 years ago) parent844da7d
2 files changed+3−1
core/src/Streamly/Internal/Data/Array/Type.hs+2−1 core/src/Streamly/Internal/Data/MutArray/Type.hs+1
core/src/Streamly/Internal/Data/Array/Type.hs+2−1
@@ -48,6 +48,7 @@ module Streamly.Internal.Data.Array.Type
4848
4949 -- ** Split
5050 , breakOn
51+ , splitAt
5152
5253 -- ** Cloning arrays
5354 , clone
@@ -61,7 +62,6 @@ module Streamly.Internal.Data.Array.Type
6162
6263 , foldl'
6364 , foldr
64− , splitAt
6565
6666 , toStreamK
6767 , toStreamKRev
@@ -559,6 +559,7 @@ foldr f z arr = runIdentity $ D.foldr f z $ toStreamD arr
559559-- | Create two slices of an array without copying the original array. The
560560-- specified index @i@ is the first index of the second slice.
561561--
562+{-# INLINE splitAt #-}
562563splitAt :: Unbox a => Int -> Array a -> (Array a, Array a)
563564splitAt i arr = (unsafeFreeze a, unsafeFreeze b)
564565 where
core/src/Streamly/Internal/Data/MutArray/Type.hs+1
@@ -2423,6 +2423,7 @@ breakOn sep arr@MutArray{..} = asUnpinnedPtrUnsafe arr $ \p -> liftIO $ do
24232423-- | Create two slices of an array without copying the original array. The
24242424-- specified index @i@ is the first index of the second slice.
24252425--
2426+{-# INLINE splitAt #-}
24262427splitAt :: forall a. Unbox a => Int -> MutArray a -> (MutArray a, MutArray a)
24272428splitAt i arr@MutArray{..} =
24282429 let maxIndex = length arr - 1