Skip to content

Commit

Permalink
Remove cloning combinators from immutable arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Feb 8, 2024
1 parent 154528f commit d86db30
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
29 changes: 0 additions & 29 deletions core/src/Streamly/Internal/Data/Array/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ module Streamly.Internal.Data.Array.Type
-- ** Construction
, empty

-- *** Cloning
-- XXX Why would we clone an immutable array?
, clone
, pinnedClone

-- *** Slicing
-- | Get a subarray without copying
, splitAt
Expand Down Expand Up @@ -415,30 +410,6 @@ fromStreamD :: forall m a. (MonadIO m, Unbox a)
=> D.Stream m a -> m (Array a)
fromStreamD = fromStream

-------------------------------------------------------------------------------
-- Cloning
-------------------------------------------------------------------------------

{-# INLINE clone #-}
clone ::
( MonadIO m
#ifdef DEVBUILD
, Unbox a
#endif
)
=> Array a -> m (Array a)
clone = fmap unsafeFreeze . MA.clone . unsafeThaw

{-# INLINE pinnedClone #-}
pinnedClone ::
( MonadIO m
#ifdef DEVBUILD
, Unbox a
#endif
)
=> Array a -> m (Array a)
pinnedClone = fmap unsafeFreeze . MA.pinnedClone . unsafeThaw

-------------------------------------------------------------------------------
-- Streams of arrays
-------------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion test/Streamly/Test/Data/Serialize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Streamly.Test.Data.Serialize.TH (genDatatype)
import Data.Functor.Identity (Identity (..))

import qualified Streamly.Internal.Data.Array as Array
import qualified Streamly.Internal.Data.MutArray as MutArray
import qualified Streamly.Internal.Data.MutByteArray as Serialize

import qualified Streamly.Test.Data.Serialize.CompatV0 as CompatV0
Expand Down Expand Up @@ -208,7 +209,8 @@ peekAndVerify (arr, serStartOff, serEndOff) val = do
off2 `shouldBe` serEndOff
let slice = Array.Array arr serStartOff serEndOff
val `shouldBe` Array.deserialize slice
clonedSlice <- Array.clone slice
clonedSlice <-
fmap Array.unsafeFreeze $ MutArray.clone $ Array.unsafeThaw $ slice
val `shouldBe` Array.deserialize clonedSlice

roundtrip
Expand Down

0 comments on commit d86db30

Please sign in to comment.