on master help sign in
Rename box and unbox to peekByteIndex and pokeByteIndex
f793f0aAdithya Kumar
core/src/Streamly/Internal/Data/Unboxed.hs+35−35
@@ -184,42 +184,42 @@ unpin arr@(MutableByteArray marr#) =
184class Storable a => Unbox a where
184class Storable a => Unbox a where
185 -- | Read an element of type "a" from a MutableByteArray given the byte
185 -- | Read an element of type "a" from a MutableByteArray given the byte
186 -- index.
186 -- index.
187− box :: MutableByteArray a -> Int -> IO a
187+ peekByteIndex :: MutableByteArray a -> Int -> IO a
188 -- | Write an element of type "a" to a MutableByteArray given the byte
188 -- | Write an element of type "a" to a MutableByteArray given the byte
189 -- index.
189 -- index.
190− unbox :: MutableByteArray a -> Int -> a -> IO ()
190+ pokeByteIndex :: MutableByteArray a -> Int -> a -> IO ()
191
191
192#define DERIVE_UNBOXED(_type, _constructor, _readArray, _writeArray) \
192#define DERIVE_UNBOXED(_type, _constructor, _readArray, _writeArray) \
193instance Unbox _type where { \
193instance Unbox _type where { \
194−; {-# INLINE box #-} \
194+; {-# INLINE peekByteIndex #-} \
195−; box (MutableByteArray mbarr) (I# n) = IO $ \s -> \
195+; peekByteIndex (MutableByteArray mbarr) (I# n) = IO $ \s -> \
196 case _readArray mbarr n s of \
196 case _readArray mbarr n s of \
197 { (# s1, i #) -> (# s1, _constructor i #) } \
197 { (# s1, i #) -> (# s1, _constructor i #) } \
198−; {-# INLINE unbox #-} \
198+; {-# INLINE pokeByteIndex #-} \
199−; unbox (MutableByteArray mbarr) (I# n) (_constructor val) = \
199+; pokeByteIndex (MutableByteArray mbarr) (I# n) (_constructor val) = \
200 IO $ \s -> (# _writeArray mbarr n val s, () #) \
200 IO $ \s -> (# _writeArray mbarr n val s, () #) \
201}
201}
202
202
203#define DERIVE_WRAPPED_UNBOX(_constraint, _type, _constructor) \
203#define DERIVE_WRAPPED_UNBOX(_constraint, _type, _constructor) \
204instance _constraint Unbox _type where \
204instance _constraint Unbox _type where \
205−; {-# INLINE box #-} \
205+; {-# INLINE peekByteIndex #-} \
206−; box arr i = _constructor <$> box (castContents arr) i \
206+; peekByteIndex arr i = _constructor <$> peekByteIndex (castContents arr) i \
207−; {-# INLINE unbox #-} \
207+; {-# INLINE pokeByteIndex #-} \
208−; unbox arr i (_constructor a) = unbox (castContents arr) i a
208+; pokeByteIndex arr i (_constructor a) = pokeByteIndex (castContents arr) i a
209
209
210#define DERIVE_BINARY_UNBOX(_constraint, _type, _constructor, _innerType) \
210#define DERIVE_BINARY_UNBOX(_constraint, _type, _constructor, _innerType) \
211instance _constraint Unbox _type where { \
211instance _constraint Unbox _type where { \
212−; {-# INLINE box #-} \
212+; {-# INLINE peekByteIndex #-} \
213−; box arr i = \
213+; peekByteIndex arr i = \
214 let contents = castContents arr :: MutableByteArray _innerType \
214 let contents = castContents arr :: MutableByteArray _innerType \
215− in box contents i >>= \
215+ in peekByteIndex contents i >>= \
216− (\p1 -> box contents (i + SIZE_OF(_innerType)) \
216+ (\p1 -> peekByteIndex contents (i + SIZE_OF(_innerType)) \
217 <&> _constructor p1) \
217 <&> _constructor p1) \
218−; {-# INLINE unbox #-} \
218+; {-# INLINE pokeByteIndex #-} \
219−; unbox arr i (_constructor p1 p2) = \
219+; pokeByteIndex arr i (_constructor p1 p2) = \
220 let contents = castContents arr :: MutableByteArray _innerType \
220 let contents = castContents arr :: MutableByteArray _innerType \
221− in unbox contents i p1 >> \
221+ in pokeByteIndex contents i p1 >> \
222− unbox contents (i + SIZE_OF(_innerType)) p2 \
222+ pokeByteIndex contents (i + SIZE_OF(_innerType)) p2 \
223}
223}
224
224
225DERIVE_UNBOXED( Char
225DERIVE_UNBOXED( Char
@@ -315,34 +315,34 @@ DERIVE_BINARY_UNBOX(,Fingerprint,Fingerprint,Word64)
315
315
316instance Unbox () where
316instance Unbox () where
317
317
318− {-# INLINE box #-}
318+ {-# INLINE peekByteIndex #-}
319− box _ _ = return ()
319+ peekByteIndex _ _ = return ()
320
320
321− {-# INLINE unbox #-}
321+ {-# INLINE pokeByteIndex #-}
322− unbox _ _ _ = return ()
322+ pokeByteIndex _ _ _ = return ()
323
323
324#if MIN_VERSION_base(4,15,0)
324#if MIN_VERSION_base(4,15,0)
325instance Unbox IoSubSystem where
325instance Unbox IoSubSystem where
326
326
327− {-# INLINE box #-}
327+ {-# INLINE peekByteIndex #-}
328− box arr i = toEnum <$> box (castContents arr) i
328+ peekByteIndex arr i = toEnum <$> peekByteIndex (castContents arr) i
329
329
330− {-# INLINE unbox #-}
330+ {-# INLINE pokeByteIndex #-}
331− unbox arr i a = unbox (castContents arr) i (fromEnum a)
331+ pokeByteIndex arr i a = pokeByteIndex (castContents arr) i (fromEnum a)
332#endif
332#endif
333
333
334instance Unbox Bool where
334instance Unbox Bool where
335
335
336− {-# INLINE box #-}
336+ {-# INLINE peekByteIndex #-}
337− box arr i = do
337+ peekByteIndex arr i = do
338− res <- box (castContents arr) i
338+ res <- peekByteIndex (castContents arr) i
339 return $ res /= (0 :: Int32)
339 return $ res /= (0 :: Int32)
340
340
341− {-# INLINE unbox #-}
341+ {-# INLINE pokeByteIndex #-}
342− unbox arr i a =
342+ pokeByteIndex arr i a =
343 if a
343 if a
344− then unbox (castContents arr) i (1 :: Int32)
344+ then pokeByteIndex (castContents arr) i (1 :: Int32)
345− else unbox (castContents arr) i (0 :: Int32)
345+ else pokeByteIndex (castContents arr) i (0 :: Int32)
346
346
347--------------------------------------------------------------------------------
347--------------------------------------------------------------------------------
348-- Functions
348-- Functions
@@ -350,8 +350,8 @@ instance Unbox Bool where
350
350
351{-# INLINE peekWith #-}
351{-# INLINE peekWith #-}
352peekWith :: Unbox a => MutableByteArray a -> Int -> IO a
352peekWith :: Unbox a => MutableByteArray a -> Int -> IO a
353−peekWith = box
353+peekWith = peekByteIndex
354
354
355{-# INLINE pokeWith #-}
355{-# INLINE pokeWith #-}
356pokeWith :: Unbox a => MutableByteArray a -> Int -> a -> IO ()
356pokeWith :: Unbox a => MutableByteArray a -> Int -> a -> IO ()
357−pokeWith = unbox
357+pokeWith = pokeByteIndex