on master help sign in
Rename MutableByteArray to MutByteArray
47b10b3Harendra Kumar
benchmark/Streamly/Benchmark/Data/Serialize.hs+3−3
@@ -326,7 +326,7 @@ benchSink name times f = bench name (nfIO (randomRIO (times, times) >>= f))
326
326
327{-
327{-
328{-# INLINE pokeWithSize #-}
328{-# INLINE pokeWithSize #-}
329−pokeWithSize :: SERIALIZE_CLASS a => MutableByteArray -> a -> IO ()
329+pokeWithSize :: SERIALIZE_CLASS a => MutByteArray -> a -> IO ()
330pokeWithSize arr val = do
330pokeWithSize arr val = do
331 let n = getSize val
331 let n = getSize val
332 n `seq` SERIALIZE_OP 0 arr val >> return ()
332 n `seq` SERIALIZE_OP 0 arr val >> return ()
@@ -340,7 +340,7 @@ pokeTimesWithSize val times = do
340-}
340-}
341
341
342{-# INLINE poke #-}
342{-# INLINE poke #-}
343−poke :: SERIALIZE_CLASS a => MutableByteArray -> a -> IO ()
343+poke :: SERIALIZE_CLASS a => MutByteArray -> a -> IO ()
344poke arr val = SERIALIZE_OP 0 arr val >> return ()
344poke arr val = SERIALIZE_OP 0 arr val >> return ()
345
345
346{-# INLINE pokeTimes #-}
346{-# INLINE pokeTimes #-}
@@ -363,7 +363,7 @@ encodeTimes val times = loop times encode val
363
363
364{-# INLINE peek #-}
364{-# INLINE peek #-}
365peek :: forall a. (NFData a, SERIALIZE_CLASS a) =>
365peek :: forall a. (NFData a, SERIALIZE_CLASS a) =>
366− (a, Int) -> MutableByteArray -> IO ()
366+ (a, Int) -> MutByteArray -> IO ()
367#ifdef USE_UNBOX
367#ifdef USE_UNBOX
368peek (_val, _) arr = do
368peek (_val, _) arr = do
369 (val1 :: a) <- DESERIALIZE_OP 0 arr
369 (val1 :: a) <- DESERIALIZE_OP 0 arr
core/src/Streamly/Data/Serialize.hs+1−1
@@ -42,7 +42,7 @@ module Streamly.Data.Serialize
42 (
42 (
43
43
44 -- * MutableByteArray
44 -- * MutableByteArray
45− MutableByteArray
45+ MutByteArray
46 -- , isPinned
46 -- , isPinned
47 -- , pin
47 -- , pin
48 -- , unpin
48 -- , unpin
core/src/Streamly/Internal/Data/Array/Type.hs+2−2
@@ -107,7 +107,7 @@ import GHC.Exts (IsList, IsString(..), Addr#)
107
107
108import GHC.IO (unsafePerformIO)
108import GHC.IO (unsafePerformIO)
109import GHC.Ptr (Ptr(..))
109import GHC.Ptr (Ptr(..))
110−import Streamly.Internal.Data.MutArray.Type (MutArray(..), MutableByteArray)
110+import Streamly.Internal.Data.MutArray.Type (MutArray(..), MutByteArray)
111import Streamly.Internal.Data.Fold.Type (Fold(..))
111import Streamly.Internal.Data.Fold.Type (Fold(..))
112import Streamly.Internal.Data.Stream.Type (Stream)
112import Streamly.Internal.Data.Stream.Type (Stream)
113import Streamly.Internal.Data.Unbox (Unbox(..))
113import Streamly.Internal.Data.Unbox (Unbox(..))
@@ -164,7 +164,7 @@ data Array a =
164#endif
164#endif
165 -- All offsets are in terms of bytes from the start of arraycontents
165 -- All offsets are in terms of bytes from the start of arraycontents
166 Array
166 Array
167− { arrContents :: {-# UNPACK #-} !MutableByteArray
167+ { arrContents :: {-# UNPACK #-} !MutByteArray
168 , arrStart :: {-# UNPACK #-} !Int -- offset
168 , arrStart :: {-# UNPACK #-} !Int -- offset
169 , arrEnd :: {-# UNPACK #-} !Int -- offset + len
169 , arrEnd :: {-# UNPACK #-} !Int -- offset + len
170 }
170 }
core/src/Streamly/Internal/Data/IORef/Unboxed.hs+2−2
@@ -41,7 +41,7 @@ where
41import Data.Proxy (Proxy(..))
41import Data.Proxy (Proxy(..))
42import Control.Monad.IO.Class (MonadIO(..))
42import Control.Monad.IO.Class (MonadIO(..))
43import Streamly.Internal.Data.Unbox
43import Streamly.Internal.Data.Unbox
44− ( MutableByteArray(..)
44+ ( MutByteArray(..)
45 , Unbox(..)
45 , Unbox(..)
46 , newBytes
46 , newBytes
47 , sizeOf
47 , sizeOf
@@ -50,7 +50,7 @@ import Streamly.Internal.Data.Unbox
50import qualified Streamly.Internal.Data.Stream.Type as D
50import qualified Streamly.Internal.Data.Stream.Type as D
51
51
52-- | An 'IORef' holds a single 'Unbox'-able value.
52-- | An 'IORef' holds a single 'Unbox'-able value.
53−newtype IORef a = IORef MutableByteArray
53+newtype IORef a = IORef MutByteArray
54
54
55-- | Create a new 'IORef'.
55-- | Create a new 'IORef'.
56--
56--
core/src/Streamly/Internal/Data/MutArray/Type.hs+9−7
@@ -31,6 +31,7 @@ module Streamly.Internal.Data.MutArray.Type
31 -- * Type
31 -- * Type
32 -- $arrayNotes
32 -- $arrayNotes
33 MutArray (..)
33 MutArray (..)
34+ , MutByteArray
34 , MutableByteArray
35 , MutableByteArray
35 , pin
36 , pin
36 , unpin
37 , unpin
@@ -239,7 +240,8 @@ import Data.Word (Word8)
239import Foreign.C.Types (CSize(..), CInt(..))
240import Foreign.C.Types (CSize(..), CInt(..))
240import Foreign.Ptr (plusPtr, minusPtr, nullPtr)
241import Foreign.Ptr (plusPtr, minusPtr, nullPtr)
241import Streamly.Internal.Data.Unbox
242import Streamly.Internal.Data.Unbox
242− ( MutableByteArray(..)
243+ ( MutByteArray(..)
244+ , MutableByteArray
243 , Unbox(..)
245 , Unbox(..)
244 , PinnedState(..)
246 , PinnedState(..)
245 , getMutableByteArray#
247 , getMutableByteArray#
@@ -343,7 +345,7 @@ data MutArray a =
343 -- The array is a range into arrContents. arrContents may be a superset of
345 -- The array is a range into arrContents. arrContents may be a superset of
344 -- the slice represented by the array. All offsets are in bytes.
346 -- the slice represented by the array. All offsets are in bytes.
345 MutArray
347 MutArray
346− { arrContents :: {-# UNPACK #-} !MutableByteArray
348+ { arrContents :: {-# UNPACK #-} !MutByteArray
347 , arrStart :: {-# UNPACK #-} !Int -- ^ index into arrContents
349 , arrStart :: {-# UNPACK #-} !Int -- ^ index into arrContents
348 , arrEnd :: {-# UNPACK #-} !Int -- ^ index into arrContents
350 , arrEnd :: {-# UNPACK #-} !Int -- ^ index into arrContents
349 -- Represents the first invalid index of
351 -- Represents the first invalid index of
@@ -405,7 +407,7 @@ isPinned MutArray{..} = Unboxed.isPinned arrContents
405-- /Pre-release/
407-- /Pre-release/
406{-# INLINE newArrayWith #-}
408{-# INLINE newArrayWith #-}
407newArrayWith :: forall m a. (MonadIO m, Unbox a)
409newArrayWith :: forall m a. (MonadIO m, Unbox a)
408− => (Int -> Int -> m MutableByteArray) -> Int -> Int -> m (MutArray a)
410+ => (Int -> Int -> m MutByteArray) -> Int -> Int -> m (MutArray a)
409newArrayWith alloc alignSize count = do
411newArrayWith alloc alignSize count = do
410 let size = max (count * SIZE_OF(a)) 0
412 let size = max (count * SIZE_OF(a)) 0
411 contents <- alloc size alignSize
413 contents <- alloc size alignSize
@@ -602,7 +604,7 @@ modify MutArray{..} f = liftIO $
602swapArrayByteIndices ::
604swapArrayByteIndices ::
603 forall a. Unbox a
605 forall a. Unbox a
604 => Proxy a
606 => Proxy a
605− -> MutableByteArray
607+ -> MutByteArray
606 -> Int
608 -> Int
607 -> Int
609 -> Int
608 -> IO ()
610 -> IO ()
@@ -744,8 +746,8 @@ reallocExplicit elemSize newCapacityInBytes MutArray{..} = do
744 if Unboxed.isPinned arrContents
746 if Unboxed.isPinned arrContents
745 then Unboxed.pinnedNewBytes newCapMaxInBytes
747 then Unboxed.pinnedNewBytes newCapMaxInBytes
746 else Unboxed.newBytes newCapMaxInBytes
748 else Unboxed.newBytes newCapMaxInBytes
747− let !(MutableByteArray mbarrFrom#) = arrContents
749+ let !(MutByteArray mbarrFrom#) = arrContents
748− !(MutableByteArray mbarrTo#) = contents
750+ !(MutByteArray mbarrTo#) = contents
749
751
750 -- Copy old data
752 -- Copy old data
751 let oldStart = arrStart
753 let oldStart = arrStart
@@ -1455,7 +1457,7 @@ flattenArraysRev (D.Stream step state) = D.Stream step' (OuterLoop state)
1455-------------------------------------------------------------------------------
1457-------------------------------------------------------------------------------
1456
1458
1457data ArrayUnsafe a = ArrayUnsafe
1459data ArrayUnsafe a = ArrayUnsafe
1458− {-# UNPACK #-} !MutableByteArray -- contents
1460+ {-# UNPACK #-} !MutByteArray -- contents
1459 {-# UNPACK #-} !Int -- index 1
1461 {-# UNPACK #-} !Int -- index 1
1460 {-# UNPACK #-} !Int -- index 2
1462 {-# UNPACK #-} !Int -- index 2
1461
1463
core/src/Streamly/Internal/Data/Serialize.hs+8−8
@@ -206,15 +206,15 @@ instance Serialize LiftedInteger where
206liftInteger :: Integer -> LiftedInteger
206liftInteger :: Integer -> LiftedInteger
207liftInteger (IS x) = LIS (I# x)
207liftInteger (IS x) = LIS (I# x)
208liftInteger (IP x) =
208liftInteger (IP x) =
209− LIP (Array (MutableByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x)))
209+ LIP (Array (MutByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x)))
210liftInteger (IN x) =
210liftInteger (IN x) =
211− LIN (Array (MutableByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x)))
211+ LIN (Array (MutByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x)))
212
212
213{-# INLINE unliftInteger #-}
213{-# INLINE unliftInteger #-}
214unliftInteger :: LiftedInteger -> Integer
214unliftInteger :: LiftedInteger -> Integer
215unliftInteger (LIS (I# x)) = IS x
215unliftInteger (LIS (I# x)) = IS x
216−unliftInteger (LIP (Array (MutableByteArray x) _ _)) = IP (unsafeCoerce# x)
216+unliftInteger (LIP (Array (MutByteArray x) _ _)) = IP (unsafeCoerce# x)
217−unliftInteger (LIN (Array (MutableByteArray x) _ _)) = IN (unsafeCoerce# x)
217+unliftInteger (LIN (Array (MutByteArray x) _ _)) = IN (unsafeCoerce# x)
218
218
219#else
219#else
220
220
@@ -222,16 +222,16 @@ unliftInteger (LIN (Array (MutableByteArray x) _ _)) = IN (unsafeCoerce# x)
222liftInteger :: Integer -> LiftedInteger
222liftInteger :: Integer -> LiftedInteger
223liftInteger (S# x) = LIS (I# x)
223liftInteger (S# x) = LIS (I# x)
224liftInteger (Jp# (BN# x)) =
224liftInteger (Jp# (BN# x)) =
225− LIP (Array (MutableByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x)))
225+ LIP (Array (MutByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x)))
226liftInteger (Jn# (BN# x)) =
226liftInteger (Jn# (BN# x)) =
227− LIN (Array (MutableByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x)))
227+ LIN (Array (MutByteArray (unsafeCoerce# x)) 0 (I# (sizeofByteArray# x)))
228
228
229{-# INLINE unliftInteger #-}
229{-# INLINE unliftInteger #-}
230unliftInteger :: LiftedInteger -> Integer
230unliftInteger :: LiftedInteger -> Integer
231unliftInteger (LIS (I# x)) = S# x
231unliftInteger (LIS (I# x)) = S# x
232−unliftInteger (LIP (Array (MutableByteArray x) _ _)) =
232+unliftInteger (LIP (Array (MutByteArray x) _ _)) =
233 Jp# (BN# (unsafeCoerce# x))
233 Jp# (BN# (unsafeCoerce# x))
234−unliftInteger (LIN (Array (MutableByteArray x) _ _)) =
234+unliftInteger (LIN (Array (MutByteArray x) _ _)) =
235 Jn# (BN# (unsafeCoerce# x))
235 Jn# (BN# (unsafeCoerce# x))
236
236
237#endif
237#endif
core/src/Streamly/Internal/Data/Serialize/TH/RecHeader.hs+3−3
@@ -27,7 +27,7 @@ import Data.Maybe (fromJust)
27import Language.Haskell.TH
27import Language.Haskell.TH
28import Streamly.Internal.Data.Serialize.Type (Serialize(..))
28import Streamly.Internal.Data.Serialize.Type (Serialize(..))
29import Data.Foldable (foldlM)
29import Data.Foldable (foldlM)
30−import Streamly.Internal.Data.Unbox (MutableByteArray)
30+import Streamly.Internal.Data.Unbox (MutByteArray)
31import Data.Proxy (Proxy(..))
31import Data.Proxy (Proxy(..))
32
32
33import qualified Streamly.Internal.Data.Unbox as Unbox
33import qualified Streamly.Internal.Data.Unbox as Unbox
@@ -225,7 +225,7 @@ headerValue (SimpleDataCon _ fields) =
225-- its type. We encode the size as 'Word32' hence there is a 4 bytes increase
225-- its type. We encode the size as 'Word32' hence there is a 4 bytes increase
226-- in size.
226-- in size.
227{-# INLINE serializeWithSize #-}
227{-# INLINE serializeWithSize #-}
228−serializeWithSize :: Serialize a => Int -> MutableByteArray -> a -> IO Int
228+serializeWithSize :: Serialize a => Int -> MutByteArray -> a -> IO Int
229serializeWithSize off arr val = do
229serializeWithSize off arr val = do
230 off1 <- serialize (off + 4) arr val
230 off1 <- serialize (off + 4) arr val
231 Unbox.pokeByteIndex off arr (int_w32 (off1 - off - 4) :: Word32)
231 Unbox.pokeByteIndex off arr (int_w32 (off1 - off - 4) :: Word32)
@@ -263,7 +263,7 @@ mkRecSerializeExpr initialOffset (con@(SimpleDataCon cname fields)) = do
263
263
264{-# INLINE deserializeWithSize #-}
264{-# INLINE deserializeWithSize #-}
265deserializeWithSize ::
265deserializeWithSize ::
266− Serialize a => Int -> MutableByteArray -> Int -> IO (Int, a)
266+ Serialize a => Int -> MutByteArray -> Int -> IO (Int, a)
267deserializeWithSize off arr endOff = deserialize (off + 4) arr endOff
267deserializeWithSize off arr endOff = deserialize (off + 4) arr endOff
268
268
269conUpdateFuncDec :: Name -> [Field] -> Q [Dec]
269conUpdateFuncDec :: Name -> [Field] -> Q [Dec]
core/src/Streamly/Internal/Data/Serialize/Type.hs+7−7
@@ -28,7 +28,7 @@ import Control.Exception (assert)
28import Data.List (foldl')
28import Data.List (foldl')
29import Data.Proxy (Proxy (..))
29import Data.Proxy (Proxy (..))
30import Streamly.Internal.Data.Unbox
30import Streamly.Internal.Data.Unbox
31− ( MutableByteArray(..)
31+ ( MutByteArray(..)
32 , PinnedState(..)
32 , PinnedState(..)
33 , Unbox
33 , Unbox
34 )
34 )
@@ -144,7 +144,7 @@ class Serialize a where
144 -- byte-offset and the deserialized value.
144 -- byte-offset and the deserialized value.
145 --
145 --
146 -- Throws an exception if the operation would exceed the supplied arrayLen.
146 -- Throws an exception if the operation would exceed the supplied arrayLen.
147− deserialize :: Int -> MutableByteArray -> Int -> IO (Int, a)
147+ deserialize :: Int -> MutByteArray -> Int -> IO (Int, a)
148
148
149 -- | @serialize byte-offset array value@ writes the serialized
149 -- | @serialize byte-offset array value@ writes the serialized
150 -- representation of the @value@ in the array at the given byte-offset.
150 -- representation of the @value@ in the array at the given byte-offset.
@@ -153,7 +153,7 @@ class Serialize a where
153 -- This is an unsafe operation, the programmer must ensure that the array
153 -- This is an unsafe operation, the programmer must ensure that the array
154 -- has enough space available to serialize the value as determined by the
154 -- has enough space available to serialize the value as determined by the
155 -- @size@ operation.
155 -- @size@ operation.
156− serialize :: Int -> MutableByteArray -> a -> IO Int
156+ serialize :: Int -> MutByteArray -> a -> IO Int
157
157
158--------------------------------------------------------------------------------
158--------------------------------------------------------------------------------
159-- Instances
159-- Instances
@@ -165,7 +165,7 @@ class Serialize a where
165--
165--
166#ifdef DEBUG
166#ifdef DEBUG
167{-# INLINE checkBounds #-}
167{-# INLINE checkBounds #-}
168−checkBounds :: String -> Int -> MutableByteArray -> IO ()
168+checkBounds :: String -> Int -> MutByteArray -> IO ()
169checkBounds _label _off _arr = do
169checkBounds _label _off _arr = do
170 sz <- sizeOfMutableByteArray _arr
170 sz <- sizeOfMutableByteArray _arr
171 if (_off > sz)
171 if (_off > sz)
@@ -196,7 +196,7 @@ checkBounds _label _off _arr = do
196-- serialized value with a size header.
196-- serialized value with a size header.
197--
197--
198{-# INLINE deserializeUnsafe #-}
198{-# INLINE deserializeUnsafe #-}
199−deserializeUnsafe :: forall a. Unbox a => Int -> MutableByteArray -> Int -> IO (Int, a)
199+deserializeUnsafe :: forall a. Unbox a => Int -> MutByteArray -> Int -> IO (Int, a)
200deserializeUnsafe off arr sz =
200deserializeUnsafe off arr sz =
201 let next = off + Unbox.sizeOf (Proxy :: Proxy a)
201 let next = off + Unbox.sizeOf (Proxy :: Proxy a)
202 in do
202 in do
@@ -209,7 +209,7 @@ deserializeUnsafe off arr sz =
209 ++ " max valid offset = " ++ show (sz - 1)
209 ++ " max valid offset = " ++ show (sz - 1)
210
210
211{-# INLINE serializeUnsafe #-}
211{-# INLINE serializeUnsafe #-}
212−serializeUnsafe :: forall a. Unbox a => Int -> MutableByteArray -> a -> IO Int
212+serializeUnsafe :: forall a. Unbox a => Int -> MutByteArray -> a -> IO Int
213serializeUnsafe off arr val =
213serializeUnsafe off arr val =
214 let next = off + Unbox.sizeOf (Proxy :: Proxy a)
214 let next = off + Unbox.sizeOf (Proxy :: Proxy a)
215 in do
215 in do
@@ -227,7 +227,7 @@ instance Serialize _type where \
227; deserialize off arr end = deserializeUnsafe off arr end :: IO (Int, _type) \
227; deserialize off arr end = deserializeUnsafe off arr end :: IO (Int, _type) \
228; {-# INLINE serialize #-} \
228; {-# INLINE serialize #-} \
229; serialize = \
229; serialize = \
230− serializeUnsafe :: Int -> MutableByteArray -> _type -> IO Int
230+ serializeUnsafe :: Int -> MutByteArray -> _type -> IO Int
231
231
232DERIVE_SERIALIZE_FROM_UNBOX(())
232DERIVE_SERIALIZE_FROM_UNBOX(())
233DERIVE_SERIALIZE_FROM_UNBOX(Bool)
233DERIVE_SERIALIZE_FROM_UNBOX(Bool)
core/src/Streamly/Internal/Data/Unbox.hs+42−38
@@ -13,8 +13,9 @@
13--
13--
14module Streamly.Internal.Data.Unbox
14module Streamly.Internal.Data.Unbox
15 (
15 (
16− -- ** MutableByteArray
16+ -- ** MutByteArray
17− MutableByteArray(..)
17+ MutByteArray(..)
18+ , MutableByteArray
18 , getMutableByteArray#
19 , getMutableByteArray#
19 , sizeOfMutableByteArray
20 , sizeOfMutableByteArray
20 , nil
21 , nil
@@ -100,23 +101,26 @@ data PinnedState
100-- | A lifted mutable byte array type wrapping @MutableByteArray# RealWorld@.
101-- | A lifted mutable byte array type wrapping @MutableByteArray# RealWorld@.
101-- This is a low level array used to back high level unboxed arrays and
102-- This is a low level array used to back high level unboxed arrays and
102-- serialized data.
103-- serialized data.
103−data MutableByteArray = MutableByteArray (MutableByteArray# RealWorld)
104+data MutByteArray = MutByteArray (MutableByteArray# RealWorld)
105+
106+{-# DEPRECATED MutableByteArray "Please use MutByteArray instead" #-}
107+type MutableByteArray = MutByteArray
104
108
105{-# INLINE getMutableByteArray# #-}
109{-# INLINE getMutableByteArray# #-}
106−getMutableByteArray# :: MutableByteArray -> MutableByteArray# RealWorld
110+getMutableByteArray# :: MutByteArray -> MutableByteArray# RealWorld
107−getMutableByteArray# (MutableByteArray mbarr) = mbarr
111+getMutableByteArray# (MutByteArray mbarr) = mbarr
108
112
109-- | Return the size of the array in bytes.
113-- | Return the size of the array in bytes.
110{-# INLINE sizeOfMutableByteArray #-}
114{-# INLINE sizeOfMutableByteArray #-}
111−sizeOfMutableByteArray :: MutableByteArray -> IO Int
115+sizeOfMutableByteArray :: MutByteArray -> IO Int
112−sizeOfMutableByteArray (MutableByteArray arr) =
116+sizeOfMutableByteArray (MutByteArray arr) =
113 IO $ \s ->
117 IO $ \s ->
114 case getSizeofMutableByteArray# arr s of
118 case getSizeofMutableByteArray# arr s of
115 (# s1, i #) -> (# s1, I# i #)
119 (# s1, i #) -> (# s1, I# i #)
116
120
117{-# INLINE touch #-}
121{-# INLINE touch #-}
118−touch :: MutableByteArray -> IO ()
122+touch :: MutByteArray -> IO ()
119−touch (MutableByteArray contents) =
123+touch (MutByteArray contents) =
120 IO $ \s -> case touch# contents s of s' -> (# s', () #)
124 IO $ \s -> case touch# contents s of s' -> (# s', () #)
121
125
122-- XXX We can provide another API for "unsafe" FFI calls passing an unlifted
126-- XXX We can provide another API for "unsafe" FFI calls passing an unlifted
@@ -131,7 +135,7 @@ touch (MutableByteArray contents) =
131-- guarantees that unsafe calls will be performed in the calling thread. Making
135-- guarantees that unsafe calls will be performed in the calling thread. Making
132-- it safe to pass heap-allocated objects to unsafe functions.
136-- it safe to pass heap-allocated objects to unsafe functions.
133
137
134−-- | Use a @MutableByteArray@ as @Ptr a@. This is useful when we want to pass
138+-- | Use a @MutByteArray@ as @Ptr a@. This is useful when we want to pass
135-- an array as a pointer to some operating system call or to a "safe" FFI call.
139-- an array as a pointer to some operating system call or to a "safe" FFI call.
136--
140--
137-- If the array is not pinned it is copied to pinned memory before passing it
141-- If the array is not pinned it is copied to pinned memory before passing it
@@ -148,7 +152,7 @@ touch (MutableByteArray contents) =
148-- /Pre-release/
152-- /Pre-release/
149--
153--
150{-# INLINE asPtrUnsafe #-}
154{-# INLINE asPtrUnsafe #-}
151−asPtrUnsafe :: MonadIO m => MutableByteArray -> (Ptr a -> m b) -> m b
155+asPtrUnsafe :: MonadIO m => MutByteArray -> (Ptr a -> m b) -> m b
152asPtrUnsafe arr f = do
156asPtrUnsafe arr f = do
153 contents <- liftIO $ pin arr
157 contents <- liftIO $ pin arr
154 let !ptr = Ptr (byteArrayContents#
158 let !ptr = Ptr (byteArrayContents#
@@ -162,41 +166,41 @@ asPtrUnsafe arr f = do
162--------------------------------------------------------------------------------
166--------------------------------------------------------------------------------
163
167
164{-# NOINLINE nil #-}
168{-# NOINLINE nil #-}
165−nil :: MutableByteArray
169+nil :: MutByteArray
166nil = unsafePerformIO $ newBytes 0
170nil = unsafePerformIO $ newBytes 0
167
171
168{-# INLINE newBytes #-}
172{-# INLINE newBytes #-}
169−newBytes :: Int -> IO MutableByteArray
173+newBytes :: Int -> IO MutByteArray
170newBytes nbytes | nbytes < 0 =
174newBytes nbytes | nbytes < 0 =
171 errorWithoutStackTrace "newBytes: size must be >= 0"
175 errorWithoutStackTrace "newBytes: size must be >= 0"
172newBytes (I# nbytes) = IO $ \s ->
176newBytes (I# nbytes) = IO $ \s ->
173 case newByteArray# nbytes s of
177 case newByteArray# nbytes s of
174 (# s', mbarr# #) ->
178 (# s', mbarr# #) ->
175− let c = MutableByteArray mbarr#
179+ let c = MutByteArray mbarr#
176 in (# s', c #)
180 in (# s', c #)
177
181
178{-# INLINE pinnedNewBytes #-}
182{-# INLINE pinnedNewBytes #-}
179−pinnedNewBytes :: Int -> IO MutableByteArray
183+pinnedNewBytes :: Int -> IO MutByteArray
180pinnedNewBytes nbytes | nbytes < 0 =
184pinnedNewBytes nbytes | nbytes < 0 =
181 errorWithoutStackTrace "pinnedNewBytes: size must be >= 0"
185 errorWithoutStackTrace "pinnedNewBytes: size must be >= 0"
182pinnedNewBytes (I# nbytes) = IO $ \s ->
186pinnedNewBytes (I# nbytes) = IO $ \s ->
183 case newPinnedByteArray# nbytes s of
187 case newPinnedByteArray# nbytes s of
184 (# s', mbarr# #) ->
188 (# s', mbarr# #) ->
185− let c = MutableByteArray mbarr#
189+ let c = MutByteArray mbarr#
186 in (# s', c #)
190 in (# s', c #)
187
191
188{-# INLINE pinnedNewAlignedBytes #-}
192{-# INLINE pinnedNewAlignedBytes #-}
189−pinnedNewAlignedBytes :: Int -> Int -> IO MutableByteArray
193+pinnedNewAlignedBytes :: Int -> Int -> IO MutByteArray
190pinnedNewAlignedBytes nbytes _align | nbytes < 0 =
194pinnedNewAlignedBytes nbytes _align | nbytes < 0 =
191 errorWithoutStackTrace "pinnedNewAlignedBytes: size must be >= 0"
195 errorWithoutStackTrace "pinnedNewAlignedBytes: size must be >= 0"
192pinnedNewAlignedBytes (I# nbytes) (I# align) = IO $ \s ->
196pinnedNewAlignedBytes (I# nbytes) (I# align) = IO $ \s ->
193 case newAlignedPinnedByteArray# nbytes align s of
197 case newAlignedPinnedByteArray# nbytes align s of
194 (# s', mbarr# #) ->
198 (# s', mbarr# #) ->
195− let c = MutableByteArray mbarr#
199+ let c = MutByteArray mbarr#
196 in (# s', c #)
200 in (# s', c #)
197
201
198{-# INLINE newBytesAs #-}
202{-# INLINE newBytesAs #-}
199−newBytesAs :: PinnedState -> Int -> IO MutableByteArray
203+newBytesAs :: PinnedState -> Int -> IO MutByteArray
200newBytesAs Unpinned = newBytes
204newBytesAs Unpinned = newBytes
201newBytesAs Pinned = pinnedNewBytes
205newBytesAs Pinned = pinnedNewBytes
202
206
@@ -209,9 +213,9 @@ newBytesAs Pinned = pinnedNewBytes
209{-# INLINE putSliceUnsafe #-}
213{-# INLINE putSliceUnsafe #-}
210putSliceUnsafe ::
214putSliceUnsafe ::
211 MonadIO m
215 MonadIO m
212− => MutableByteArray
216+ => MutByteArray
213 -> Int
217 -> Int
214− -> MutableByteArray
218+ -> MutByteArray
215 -> Int
219 -> Int
216 -> Int
220 -> Int
217 -> m ()
221 -> m ()
@@ -236,8 +240,8 @@ putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do
236-------------------------------------------------------------------------------
240-------------------------------------------------------------------------------
237
241
238{-# INLINE isPinned #-}
242{-# INLINE isPinned #-}
239−isPinned :: MutableByteArray -> Bool
243+isPinned :: MutByteArray -> Bool
240−isPinned (MutableByteArray arr#) =
244+isPinned (MutByteArray arr#) =
241 let pinnedInt = I# (isMutableByteArrayPinned# arr#)
245 let pinnedInt = I# (isMutableByteArrayPinned# arr#)
242 in pinnedInt /= 0
246 in pinnedInt /= 0
243
247
@@ -258,8 +262,8 @@ cloneMutableArrayWith# alloc# arr# s# =
258 s3# -> (# s3#, arr1# #)
262 s3# -> (# s3#, arr1# #)
259
263
260{-# INLINE pin #-}
264{-# INLINE pin #-}
261−pin :: MutableByteArray -> IO MutableByteArray
265+pin :: MutByteArray -> IO MutByteArray
262−pin arr@(MutableByteArray marr#) =
266+pin arr@(MutByteArray marr#) =
263 if isPinned arr
267 if isPinned arr
264 then return arr
268 then return arr
265 else
269 else
@@ -271,11 +275,11 @@ pin arr@(MutableByteArray marr#) =
271 IO
275 IO
272 $ \s# ->
276 $ \s# ->
273 case cloneMutableArrayWith# newPinnedByteArray# marr# s# of
277 case cloneMutableArrayWith# newPinnedByteArray# marr# s# of
274− (# s1#, marr1# #) -> (# s1#, MutableByteArray marr1# #)
278+ (# s1#, marr1# #) -> (# s1#, MutByteArray marr1# #)
275
279
276{-# INLINE unpin #-}
280{-# INLINE unpin #-}
277−unpin :: MutableByteArray -> IO MutableByteArray
281+unpin :: MutByteArray -> IO MutByteArray
278−unpin arr@(MutableByteArray marr#) =
282+unpin arr@(MutByteArray marr#) =
279 if not (isPinned arr)
283 if not (isPinned arr)
280 then return arr
284 then return arr
281 else
285 else
@@ -287,7 +291,7 @@ unpin arr@(MutableByteArray marr#) =
287 IO
291 IO
288 $ \s# ->
292 $ \s# ->
289 case cloneMutableArrayWith# newByteArray# marr# s# of
293 case cloneMutableArrayWith# newByteArray# marr# s# of
290− (# s1#, marr1# #) -> (# s1#, MutableByteArray marr1# #)
294+ (# s1#, marr1# #) -> (# s1#, MutByteArray marr1# #)
291
295
292--------------------------------------------------------------------------------
296--------------------------------------------------------------------------------
293-- The Unbox type class
297-- The Unbox type class
@@ -458,11 +462,11 @@ class Unbox a where
458 --
462 --
459 -- IMPORTANT: The implementation of this interface may not check the bounds
463 -- IMPORTANT: The implementation of this interface may not check the bounds
460 -- of the array, the caller must not assume that.
464 -- of the array, the caller must not assume that.
461− peekByteIndex :: Int -> MutableByteArray -> IO a
465+ peekByteIndex :: Int -> MutByteArray -> IO a
462
466
463 {-# INLINE peekByteIndex #-}
467 {-# INLINE peekByteIndex #-}
464 default peekByteIndex :: (Generic a, PeekRep (Rep a)) =>
468 default peekByteIndex :: (Generic a, PeekRep (Rep a)) =>
465− Int -> MutableByteArray -> IO a
469+ Int -> MutByteArray -> IO a
466 peekByteIndex i arr = genericPeekByteIndex arr i
470 peekByteIndex i arr = genericPeekByteIndex arr i
467
471
468 -- | @pokeByteIndex byte-index array@ writes an element of type @a@ to the
472 -- | @pokeByteIndex byte-index array@ writes an element of type @a@ to the
@@ -470,11 +474,11 @@ class Unbox a where
470 --
474 --
471 -- IMPORTANT: The implementation of this interface may not check the bounds
475 -- IMPORTANT: The implementation of this interface may not check the bounds
472 -- of the array, the caller must not assume that.
476 -- of the array, the caller must not assume that.
473− pokeByteIndex :: Int -> MutableByteArray -> a -> IO ()
477+ pokeByteIndex :: Int -> MutByteArray -> a -> IO ()
474
478
475 {-# INLINE pokeByteIndex #-}
479 {-# INLINE pokeByteIndex #-}
476 default pokeByteIndex :: (Generic a, PokeRep (Rep a)) =>
480 default pokeByteIndex :: (Generic a, PokeRep (Rep a)) =>
477− Int -> MutableByteArray -> a -> IO ()
481+ Int -> MutByteArray -> a -> IO ()
478 pokeByteIndex i arr = genericPokeByteIndex arr i
482 pokeByteIndex i arr = genericPokeByteIndex arr i
479
483
480-- XXX Add asserts to check bounds
484-- XXX Add asserts to check bounds
@@ -482,11 +486,11 @@ class Unbox a where
482#define DERIVE_UNBOXED(_type, _constructor, _readArray, _writeArray, _sizeOf) \
486#define DERIVE_UNBOXED(_type, _constructor, _readArray, _writeArray, _sizeOf) \
483instance Unbox _type where { \
487instance Unbox _type where { \
484; {-# INLINE peekByteIndex #-} \
488; {-# INLINE peekByteIndex #-} \
485−; peekByteIndex (I# n) (MutableByteArray mbarr) = IO $ \s -> \
489+; peekByteIndex (I# n) (MutByteArray mbarr) = IO $ \s -> \
486 case _readArray mbarr n s of \
490 case _readArray mbarr n s of \
487 { (# s1, i #) -> (# s1, _constructor i #) } \
491 { (# s1, i #) -> (# s1, _constructor i #) } \
488; {-# INLINE pokeByteIndex #-} \
492; {-# INLINE pokeByteIndex #-} \
489−; pokeByteIndex (I# n) (MutableByteArray mbarr) (_constructor val) = \
493+; pokeByteIndex (I# n) (MutByteArray mbarr) (_constructor val) = \
490 IO $ \s -> (# _writeArray mbarr n val s, () #) \
494 IO $ \s -> (# _writeArray mbarr n val s, () #) \
491; {-# INLINE sizeOf #-} \
495; {-# INLINE sizeOf #-} \
492; sizeOf _ = _sizeOf \
496; sizeOf _ = _sizeOf \
@@ -681,7 +685,7 @@ instance Unbox Bool where
681-- cheaper to just get the bound using the size of the array whenever needed?
685-- cheaper to just get the bound using the size of the array whenever needed?
682data BoundedPtr =
686data BoundedPtr =
683 BoundedPtr
687 BoundedPtr
684− MutableByteArray -- byte array
688+ MutByteArray -- byte array
685 Int -- current pos
689 Int -- current pos
686 Int -- position after end
690 Int -- position after end
687
691
@@ -966,7 +970,7 @@ genericPokeObj a ptr = void $ genericPokeObject a ptr
966
970
967{-# INLINE genericPokeByteIndex #-}
971{-# INLINE genericPokeByteIndex #-}
968genericPokeByteIndex :: (Generic a, PokeRep (Rep a)) =>
972genericPokeByteIndex :: (Generic a, PokeRep (Rep a)) =>
969− MutableByteArray -> Int -> a -> IO ()
973+ MutByteArray -> Int -> a -> IO ()
970genericPokeByteIndex arr index x = do
974genericPokeByteIndex arr index x = do
971 -- XXX Should we use unsafe poke?
975 -- XXX Should we use unsafe poke?
972#ifdef DEBUG
976#ifdef DEBUG
@@ -1072,7 +1076,7 @@ genericPeekBoundedPtr = runPeeker genericPeeker
1072
1076
1073{-# INLINE genericPeekByteIndex #-}
1077{-# INLINE genericPeekByteIndex #-}
1074genericPeekByteIndex :: (Generic a, PeekRep (Rep a)) =>
1078genericPeekByteIndex :: (Generic a, PeekRep (Rep a)) =>
1075− MutableByteArray -> Int -> IO a
1079+ MutByteArray -> Int -> IO a
1076genericPeekByteIndex arr index = do
1080genericPeekByteIndex arr index = do
1077 -- XXX Should we use unsafe peek?
1081 -- XXX Should we use unsafe peek?
1078#ifdef DEBUG
1082#ifdef DEBUG
core/src/Streamly/Internal/Unicode/Stream.hs+4−4
@@ -109,7 +109,7 @@ import GHC.IO.Encoding.Failure (isSurrogate)
109import GHC.Ptr (Ptr (..), plusPtr)
109import GHC.Ptr (Ptr (..), plusPtr)
110import System.IO.Unsafe (unsafePerformIO)
110import System.IO.Unsafe (unsafePerformIO)
111import Streamly.Internal.Data.Array.Type (Array(..))
111import Streamly.Internal.Data.Array.Type (Array(..))
112−import Streamly.Internal.Data.MutArray.Type (MutableByteArray)
112+import Streamly.Internal.Data.MutArray.Type (MutByteArray)
113import Streamly.Internal.Data.Fold (Fold)
113import Streamly.Internal.Data.Fold (Fold)
114import Streamly.Internal.Data.Parser (Parser)
114import Streamly.Internal.Data.Parser (Parser)
115import Streamly.Internal.Data.Stream (Stream)
115import Streamly.Internal.Data.Stream (Stream)
@@ -685,9 +685,9 @@ decodeUtf8Lax = decodeUtf8
685#endif
685#endif
686data FlattenState s
686data FlattenState s
687 = OuterLoop s !(Maybe (DecodeState, CodePoint))
687 = OuterLoop s !(Maybe (DecodeState, CodePoint))
688− | InnerLoopDecodeInit s MutableByteArray !Int !Int
688+ | InnerLoopDecodeInit s MutByteArray !Int !Int
689− | InnerLoopDecodeFirst s MutableByteArray !Int !Int Word8
689+ | InnerLoopDecodeFirst s MutByteArray !Int !Int Word8
690− | InnerLoopDecoding s MutableByteArray !Int !Int
690+ | InnerLoopDecoding s MutByteArray !Int !Int
691 !DecodeState !CodePoint
691 !DecodeState !CodePoint
692 | YAndC !Char (FlattenState s) -- These constructors can be
692 | YAndC !Char (FlattenState s) -- These constructors can be
693 -- encoded in the UTF8DecodeState
693 -- encoded in the UTF8DecodeState
test/Streamly/Test/Data/Serialize.hs+3−3
@@ -22,7 +22,7 @@ module Streamly.Test.Data.Serialize (main) where
22--------------------------------------------------------------------------------
22--------------------------------------------------------------------------------
23
23
24import System.Random (randomRIO)
24import System.Random (randomRIO)
25−import Streamly.Internal.Data.Serialize (MutableByteArray, newBytes)
25+import Streamly.Internal.Data.Serialize (MutByteArray, newBytes)
26import GHC.Generics (Generic)
26import GHC.Generics (Generic)
27import Streamly.Data.Serialize (Serialize)
27import Streamly.Data.Serialize (Serialize)
28import Streamly.Test.Data.Serialize.TH (genDatatype)
28import Streamly.Test.Data.Serialize.TH (genDatatype)
@@ -158,7 +158,7 @@ testCompatibility v0 v1 = do
158poke ::
158poke ::
159 forall a. Serialize.Serialize a
159 forall a. Serialize.Serialize a
160 => a
160 => a
161− -> IO (MutableByteArray, Int, Int)
161+ -> IO (MutByteArray, Int, Int)
162poke val = do
162poke val = do
163 let sz = Serialize.size 0 val
163 let sz = Serialize.size 0 val
164
164
@@ -177,7 +177,7 @@ poke val = do
177
177
178peekAndVerify ::
178peekAndVerify ::
179 forall a. (Eq a, Show a, Serialize.Serialize a)
179 forall a. (Eq a, Show a, Serialize.Serialize a)
180− => (MutableByteArray, Int, Int)
180+ => (MutByteArray, Int, Int)
181 -> a
181 -> a
182 -> IO ()
182 -> IO ()
183peekAndVerify (arr, serStartOff, serEndOff) val = do
183peekAndVerify (arr, serStartOff, serEndOff) val = do
test/Streamly/Test/Data/Unbox.hs+2−2
@@ -72,7 +72,7 @@ import Test.Hspec as H
72peekByteIndexWithNextOff ::
72peekByteIndexWithNextOff ::
73 forall a. Unbox a
73 forall a. Unbox a
74 => Int
74 => Int
75− -> MutableByteArray
75+ -> MutByteArray
76 -> IO (Int, a)
76 -> IO (Int, a)
77peekByteIndexWithNextOff i arr = do
77peekByteIndexWithNextOff i arr = do
78 val <- peekByteIndex i arr
78 val <- peekByteIndex i arr
@@ -81,7 +81,7 @@ peekByteIndexWithNextOff i arr = do
81pokeByteIndexWithNextOff ::
81pokeByteIndexWithNextOff ::
82 forall a. Unbox a
82 forall a. Unbox a
83 => Int
83 => Int
84− -> MutableByteArray
84+ -> MutByteArray
85 -> a
85 -> a
86 -> IO Int
86 -> IO Int
87pokeByteIndexWithNextOff i arr val = do
87pokeByteIndexWithNextOff i arr val = do