@@ -13,8 +13,9 @@
1313--
1414module Streamly.Internal.Data.Unbox
1515 (
16− -- ** MutableByteArray
17− MutableByteArray(..)
16+ -- ** MutByteArray
17+ MutByteArray(..)
18+ , MutableByteArray
1819 , getMutableByteArray#
1920 , sizeOfMutableByteArray
2021 , nil
@@ -100,23 +101,26 @@ data PinnedState
100101-- | A lifted mutable byte array type wrapping @MutableByteArray# RealWorld@.
101102-- This is a low level array used to back high level unboxed arrays and
102103-- 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
104108
105109{-# INLINE getMutableByteArray# #-}
106−getMutableByteArray# :: MutableByteArray -> MutableByteArray# RealWorld
107−getMutableByteArray# (MutableByteArray mbarr) = mbarr
110+getMutableByteArray# :: MutByteArray -> MutableByteArray# RealWorld
111+getMutableByteArray# (MutByteArray mbarr) = mbarr
108112
109113-- | Return the size of the array in bytes.
110114{-# INLINE sizeOfMutableByteArray #-}
111−sizeOfMutableByteArray :: MutableByteArray -> IO Int
112−sizeOfMutableByteArray (MutableByteArray arr) =
115+sizeOfMutableByteArray :: MutByteArray -> IO Int
116+sizeOfMutableByteArray (MutByteArray arr) =
113117 IO $ \s ->
114118 case getSizeofMutableByteArray# arr s of
115119 (# s1, i #) -> (# s1, I# i #)
116120
117121{-# INLINE touch #-}
118−touch :: MutableByteArray -> IO ()
119−touch (MutableByteArray contents) =
122+touch :: MutByteArray -> IO ()
123+touch (MutByteArray contents) =
120124 IO $ \s -> case touch# contents s of s' -> (# s', () #)
121125
122126-- XXX We can provide another API for "unsafe" FFI calls passing an unlifted
@@ -131,7 +135,7 @@ touch (MutableByteArray contents) =
131135-- guarantees that unsafe calls will be performed in the calling thread. Making
132136-- it safe to pass heap-allocated objects to unsafe functions.
133137
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
135139-- an array as a pointer to some operating system call or to a "safe" FFI call.
136140--
137141-- If the array is not pinned it is copied to pinned memory before passing it
@@ -148,7 +152,7 @@ touch (MutableByteArray contents) =
148152-- /Pre-release/
149153--
150154{-# INLINE asPtrUnsafe #-}
151−asPtrUnsafe :: MonadIO m => MutableByteArray -> (Ptr a -> m b) -> m b
155+asPtrUnsafe :: MonadIO m => MutByteArray -> (Ptr a -> m b) -> m b
152156asPtrUnsafe arr f = do
153157 contents <- liftIO $ pin arr
154158 let !ptr = Ptr (byteArrayContents#
@@ -162,41 +166,41 @@ asPtrUnsafe arr f = do
162166--------------------------------------------------------------------------------
163167
164168{-# NOINLINE nil #-}
165−nil :: MutableByteArray
169+nil :: MutByteArray
166170nil = unsafePerformIO $ newBytes 0
167171
168172{-# INLINE newBytes #-}
169−newBytes :: Int -> IO MutableByteArray
173+newBytes :: Int -> IO MutByteArray
170174newBytes nbytes | nbytes < 0 =
171175 errorWithoutStackTrace "newBytes: size must be >= 0"
172176newBytes (I# nbytes) = IO $ \s ->
173177 case newByteArray# nbytes s of
174178 (# s', mbarr# #) ->
175− let c = MutableByteArray mbarr#
179+ let c = MutByteArray mbarr#
176180 in (# s', c #)
177181
178182{-# INLINE pinnedNewBytes #-}
179−pinnedNewBytes :: Int -> IO MutableByteArray
183+pinnedNewBytes :: Int -> IO MutByteArray
180184pinnedNewBytes nbytes | nbytes < 0 =
181185 errorWithoutStackTrace "pinnedNewBytes: size must be >= 0"
182186pinnedNewBytes (I# nbytes) = IO $ \s ->
183187 case newPinnedByteArray# nbytes s of
184188 (# s', mbarr# #) ->
185− let c = MutableByteArray mbarr#
189+ let c = MutByteArray mbarr#
186190 in (# s', c #)
187191
188192{-# INLINE pinnedNewAlignedBytes #-}
189−pinnedNewAlignedBytes :: Int -> Int -> IO MutableByteArray
193+pinnedNewAlignedBytes :: Int -> Int -> IO MutByteArray
190194pinnedNewAlignedBytes nbytes _align | nbytes < 0 =
191195 errorWithoutStackTrace "pinnedNewAlignedBytes: size must be >= 0"
192196pinnedNewAlignedBytes (I# nbytes) (I# align) = IO $ \s ->
193197 case newAlignedPinnedByteArray# nbytes align s of
194198 (# s', mbarr# #) ->
195− let c = MutableByteArray mbarr#
199+ let c = MutByteArray mbarr#
196200 in (# s', c #)
197201
198202{-# INLINE newBytesAs #-}
199−newBytesAs :: PinnedState -> Int -> IO MutableByteArray
203+newBytesAs :: PinnedState -> Int -> IO MutByteArray
200204newBytesAs Unpinned = newBytes
201205newBytesAs Pinned = pinnedNewBytes
202206
@@ -209,9 +213,9 @@ newBytesAs Pinned = pinnedNewBytes
209213{-# INLINE putSliceUnsafe #-}
210214putSliceUnsafe ::
211215 MonadIO m
212− => MutableByteArray
216+ => MutByteArray
213217 -> Int
214− -> MutableByteArray
218+ -> MutByteArray
215219 -> Int
216220 -> Int
217221 -> m ()
@@ -236,8 +240,8 @@ putSliceUnsafe src srcStartBytes dst dstStartBytes lenBytes = liftIO $ do
236240-------------------------------------------------------------------------------
237241
238242{-# INLINE isPinned #-}
239−isPinned :: MutableByteArray -> Bool
240−isPinned (MutableByteArray arr#) =
243+isPinned :: MutByteArray -> Bool
244+isPinned (MutByteArray arr#) =
241245 let pinnedInt = I# (isMutableByteArrayPinned# arr#)
242246 in pinnedInt /= 0
243247
@@ -258,8 +262,8 @@ cloneMutableArrayWith# alloc# arr# s# =
258262 s3# -> (# s3#, arr1# #)
259263
260264{-# INLINE pin #-}
261−pin :: MutableByteArray -> IO MutableByteArray
262−pin arr@(MutableByteArray marr#) =
265+pin :: MutByteArray -> IO MutByteArray
266+pin arr@(MutByteArray marr#) =
263267 if isPinned arr
264268 then return arr
265269 else
@@ -271,11 +275,11 @@ pin arr@(MutableByteArray marr#) =
271275 IO
272276 $ \s# ->
273277 case cloneMutableArrayWith# newPinnedByteArray# marr# s# of
274− (# s1#, marr1# #) -> (# s1#, MutableByteArray marr1# #)
278+ (# s1#, marr1# #) -> (# s1#, MutByteArray marr1# #)
275279
276280{-# INLINE unpin #-}
277−unpin :: MutableByteArray -> IO MutableByteArray
278−unpin arr@(MutableByteArray marr#) =
281+unpin :: MutByteArray -> IO MutByteArray
282+unpin arr@(MutByteArray marr#) =
279283 if not (isPinned arr)
280284 then return arr
281285 else
@@ -287,7 +291,7 @@ unpin arr@(MutableByteArray marr#) =
287291 IO
288292 $ \s# ->
289293 case cloneMutableArrayWith# newByteArray# marr# s# of
290− (# s1#, marr1# #) -> (# s1#, MutableByteArray marr1# #)
294+ (# s1#, marr1# #) -> (# s1#, MutByteArray marr1# #)
291295
292296--------------------------------------------------------------------------------
293297-- The Unbox type class
@@ -458,11 +462,11 @@ class Unbox a where
458462 --
459463 -- IMPORTANT: The implementation of this interface may not check the bounds
460464 -- of the array, the caller must not assume that.
461− peekByteIndex :: Int -> MutableByteArray -> IO a
465+ peekByteIndex :: Int -> MutByteArray -> IO a
462466
463467 {-# INLINE peekByteIndex #-}
464468 default peekByteIndex :: (Generic a, PeekRep (Rep a)) =>
465− Int -> MutableByteArray -> IO a
469+ Int -> MutByteArray -> IO a
466470 peekByteIndex i arr = genericPeekByteIndex arr i
467471
468472 -- | @pokeByteIndex byte-index array@ writes an element of type @a@ to the
@@ -470,11 +474,11 @@ class Unbox a where
470474 --
471475 -- IMPORTANT: The implementation of this interface may not check the bounds
472476 -- of the array, the caller must not assume that.
473− pokeByteIndex :: Int -> MutableByteArray -> a -> IO ()
477+ pokeByteIndex :: Int -> MutByteArray -> a -> IO ()
474478
475479 {-# INLINE pokeByteIndex #-}
476480 default pokeByteIndex :: (Generic a, PokeRep (Rep a)) =>
477− Int -> MutableByteArray -> a -> IO ()
481+ Int -> MutByteArray -> a -> IO ()
478482 pokeByteIndex i arr = genericPokeByteIndex arr i
479483
480484-- XXX Add asserts to check bounds
@@ -482,11 +486,11 @@ class Unbox a where
482486#define DERIVE_UNBOXED(_type, _constructor, _readArray, _writeArray, _sizeOf) \
483487instance Unbox _type where { \
484488; {-# INLINE peekByteIndex #-} \
485−; peekByteIndex (I# n) (MutableByteArray mbarr) = IO $ \s -> \
489+; peekByteIndex (I# n) (MutByteArray mbarr) = IO $ \s -> \
486490 case _readArray mbarr n s of \
487491 { (# s1, i #) -> (# s1, _constructor i #) } \
488492; {-# INLINE pokeByteIndex #-} \
489−; pokeByteIndex (I# n) (MutableByteArray mbarr) (_constructor val) = \
493+; pokeByteIndex (I# n) (MutByteArray mbarr) (_constructor val) = \
490494 IO $ \s -> (# _writeArray mbarr n val s, () #) \
491495; {-# INLINE sizeOf #-} \
492496; sizeOf _ = _sizeOf \
@@ -681,7 +685,7 @@ instance Unbox Bool where
681685-- cheaper to just get the bound using the size of the array whenever needed?
682686data BoundedPtr =
683687 BoundedPtr
684− MutableByteArray -- byte array
688+ MutByteArray -- byte array
685689 Int -- current pos
686690 Int -- position after end
687691
@@ -966,7 +970,7 @@ genericPokeObj a ptr = void $ genericPokeObject a ptr
966970
967971{-# INLINE genericPokeByteIndex #-}
968972genericPokeByteIndex :: (Generic a, PokeRep (Rep a)) =>
969− MutableByteArray -> Int -> a -> IO ()
973+ MutByteArray -> Int -> a -> IO ()
970974genericPokeByteIndex arr index x = do
971975 -- XXX Should we use unsafe poke?
972976#ifdef DEBUG
@@ -1072,7 +1076,7 @@ genericPeekBoundedPtr = runPeeker genericPeeker
10721076
10731077{-# INLINE genericPeekByteIndex #-}
10741078genericPeekByteIndex :: (Generic a, PeekRep (Rep a)) =>
1075− MutableByteArray -> Int -> IO a
1079+ MutByteArray -> Int -> IO a
10761080genericPeekByteIndex arr index = do
10771081 -- XXX Should we use unsafe peek?
10781082#ifdef DEBUG