@@ -254,15 +254,15 @@ unpin arr@(MutableByteArray marr#) =
255-- instance Unbox Object where
255-- instance Unbox Object where
256-- sizeOf _ = 16
256-- sizeOf _ = 16
257−-- peekByteIndex arr i = do
257+-- peekByteIndex i arr = do
258-- let p = castContents arr
258-- let p = castContents arr
259−-- x0 <- peekByteIndex p i
259+-- x0 <- peekByteIndex i p
260−-- x1 <- peekByteIndex p (i + 8)
260+-- x1 <- peekByteIndex (i + 8) p
261-- return $ Object x0 x1
261-- return $ Object x0 x1
262−-- pokeByteIndex arr i (Object x0 x1) = do
262+-- pokeByteIndex i arr (Object x0 x1) = do
263-- let p = castContents arr
263-- let p = castContents arr
264−-- pokeByteIndex p i x0
264+-- pokeByteIndex i p x0
265−-- pokeByteIndex p (i + 8) x1
265+-- pokeByteIndex (i + 8) p x1
268class Unbox a where
268class Unbox a where
@@ -277,31 +277,31 @@ class Unbox a where
278 -- IMPORTANT: The implementation of this interface may not check the bounds
278 -- IMPORTANT: The implementation of this interface may not check the bounds
279 -- of the array, the caller must not assume that.
279 -- of the array, the caller must not assume that.
280− peekByteIndex :: MutableByteArray a -> Int -> IO a
280+ peekByteIndex :: Int -> MutableByteArray a -> IO a
282 default peekByteIndex :: (Generic a, PeekRep (Rep a)) =>
282 default peekByteIndex :: (Generic a, PeekRep (Rep a)) =>
283− MutableByteArray a -> Int -> IO a
283+ Int -> MutableByteArray a -> IO a
284− peekByteIndex = genericPeekByteIndex
284+ peekByteIndex i arr = genericPeekByteIndex arr i
286 -- | Write an element of type "a" to a MutableByteArray given the byte
286 -- | Write an element of type "a" to a MutableByteArray given the byte
287 -- index.
287 -- index.
289 -- IMPORTANT: The implementation of this interface may not check the bounds
289 -- IMPORTANT: The implementation of this interface may not check the bounds
290 -- of the array, the caller must not assume that.
290 -- of the array, the caller must not assume that.
291− pokeByteIndex :: MutableByteArray a -> Int -> a -> IO ()
291+ pokeByteIndex :: Int -> MutableByteArray a -> a -> IO ()
293 default pokeByteIndex :: (Generic a, PokeRep (Rep a)) =>
293 default pokeByteIndex :: (Generic a, PokeRep (Rep a)) =>
294− MutableByteArray a -> Int -> a -> IO ()
294+ Int -> MutableByteArray a -> a -> IO ()
295− pokeByteIndex = genericPokeByteIndex
295+ pokeByteIndex i arr = genericPokeByteIndex arr i
297#define DERIVE_UNBOXED(_type, _constructor, _readArray, _writeArray, _sizeOf) \
297#define DERIVE_UNBOXED(_type, _constructor, _readArray, _writeArray, _sizeOf) \
298instance Unbox _type where { \
298instance Unbox _type where { \
299; {-# INLINE peekByteIndex #-} \
299; {-# INLINE peekByteIndex #-} \
300−; peekByteIndex (MutableByteArray mbarr) (I# n) = IO $ \s -> \
300+; peekByteIndex (I# n) (MutableByteArray mbarr) = IO $ \s -> \
301 case _readArray mbarr n s of \
301 case _readArray mbarr n s of \
302 { (# s1, i #) -> (# s1, _constructor i #) } \
302 { (# s1, i #) -> (# s1, _constructor i #) } \
303; {-# INLINE pokeByteIndex #-} \
303; {-# INLINE pokeByteIndex #-} \
304−; pokeByteIndex (MutableByteArray mbarr) (I# n) (_constructor val) = \
304+; pokeByteIndex (I# n) (MutableByteArray mbarr) (_constructor val) = \
305 IO $ \s -> (# _writeArray mbarr n val s, () #) \
305 IO $ \s -> (# _writeArray mbarr n val s, () #) \
306; {-# INLINE sizeOf #-} \
306; {-# INLINE sizeOf #-} \
307; sizeOf _ = _sizeOf \
307; sizeOf _ = _sizeOf \
@@ -310,25 +310,25 @@ instance Unbox _type where { \
310#define DERIVE_WRAPPED_UNBOX(_constraint, _type, _constructor, _innerType) \
310#define DERIVE_WRAPPED_UNBOX(_constraint, _type, _constructor, _innerType) \
311instance _constraint Unbox _type where \
311instance _constraint Unbox _type where \
312; {-# INLINE peekByteIndex #-} \
312; {-# INLINE peekByteIndex #-} \
313−; peekByteIndex arr i = _constructor <$> peekByteIndex (castContents arr) i \
313+; peekByteIndex i arr = _constructor <$> peekByteIndex i (castContents arr) \
314; {-# INLINE pokeByteIndex #-} \
314; {-# INLINE pokeByteIndex #-} \
315−; pokeByteIndex arr i (_constructor a) = pokeByteIndex (castContents arr) i a \
315+; pokeByteIndex i arr (_constructor a) = pokeByteIndex i (castContents arr) a \
316; {-# INLINE sizeOf #-} \
316; {-# INLINE sizeOf #-} \
317; sizeOf _ = SIZE_OF(_innerType)
317; sizeOf _ = SIZE_OF(_innerType)
319#define DERIVE_BINARY_UNBOX(_constraint, _type, _constructor, _innerType) \
319#define DERIVE_BINARY_UNBOX(_constraint, _type, _constructor, _innerType) \
320instance _constraint Unbox _type where { \
320instance _constraint Unbox _type where { \
321; {-# INLINE peekByteIndex #-} \
321; {-# INLINE peekByteIndex #-} \
322−; peekByteIndex arr i = \
322+; peekByteIndex i arr = \
323 let contents = castContents arr :: MutableByteArray _innerType \
323 let contents = castContents arr :: MutableByteArray _innerType \
324− in peekByteIndex contents i >>= \
324+ in peekByteIndex i contents >>= \
325− (\p1 -> peekByteIndex contents (i + SIZE_OF(_innerType)) \
325+ (\p1 -> peekByteIndex (i + SIZE_OF(_innerType)) contents \
326 <&> _constructor p1) \
326 <&> _constructor p1) \
327; {-# INLINE pokeByteIndex #-} \
327; {-# INLINE pokeByteIndex #-} \
328−; pokeByteIndex arr i (_constructor p1 p2) = \
328+; pokeByteIndex i arr (_constructor p1 p2) = \
329 let contents = castContents arr :: MutableByteArray _innerType \
329 let contents = castContents arr :: MutableByteArray _innerType \
330− in pokeByteIndex contents i p1 >> \
330+ in pokeByteIndex i contents p1 >> \
331− pokeByteIndex contents (i + SIZE_OF(_innerType)) p2 \
331+ pokeByteIndex (i + SIZE_OF(_innerType)) contents p2 \
332; {-# INLINE sizeOf #-} \
332; {-# INLINE sizeOf #-} \
333; sizeOf _ = 2 * SIZE_OF(_innerType) \
333; sizeOf _ = 2 * SIZE_OF(_innerType) \
@@ -455,10 +455,10 @@ instance Unbox () where
455instance Unbox IoSubSystem where
455instance Unbox IoSubSystem where
457 {-# INLINE peekByteIndex #-}
457 {-# INLINE peekByteIndex #-}
458− peekByteIndex arr i = toEnum <$> peekByteIndex (castContents arr) i
458+ peekByteIndex i arr = toEnum <$> peekByteIndex i (castContents arr)
460 {-# INLINE pokeByteIndex #-}
460 {-# INLINE pokeByteIndex #-}
461− pokeByteIndex arr i a = pokeByteIndex (castContents arr) i (fromEnum a)
461+ pokeByteIndex i arr a = pokeByteIndex i (castContents arr) (fromEnum a)
463 {-# INLINE sizeOf #-}
463 {-# INLINE sizeOf #-}
464 sizeOf = sizeOf . fromEnum
464 sizeOf = sizeOf . fromEnum
@@ -467,15 +467,15 @@ instance Unbox IoSubSystem where
467instance Unbox Bool where
467instance Unbox Bool where
469 {-# INLINE peekByteIndex #-}
469 {-# INLINE peekByteIndex #-}
470− peekByteIndex arr i = do
470+ peekByteIndex i arr = do
471− res <- peekByteIndex (castContents arr) i
471+ res <- peekByteIndex i (castContents arr)
472 return $ res /= (0 :: Int8)
472 return $ res /= (0 :: Int8)
474 {-# INLINE pokeByteIndex #-}
474 {-# INLINE pokeByteIndex #-}
475− pokeByteIndex arr i a =
475+ pokeByteIndex i arr a =
477− then pokeByteIndex (castContents arr) i (1 :: Int8)
477+ then pokeByteIndex i (castContents arr) (1 :: Int8)
478− else pokeByteIndex (castContents arr) i (0 :: Int8)
478+ else pokeByteIndex i (castContents arr) (0 :: Int8)
480 {-# INLINE sizeOf #-}
480 {-# INLINE sizeOf #-}
481 sizeOf _ = 1
481 sizeOf _ = 1
@@ -486,11 +486,11 @@ instance Unbox Bool where
487{-# INLINE peekWith #-}
487{-# INLINE peekWith #-}
488peekWith :: Unbox a => MutableByteArray a -> Int -> IO a
488peekWith :: Unbox a => MutableByteArray a -> Int -> IO a
489−peekWith = peekByteIndex
489+peekWith arr i = peekByteIndex i arr
491{-# INLINE pokeWith #-}
491{-# INLINE pokeWith #-}
492pokeWith :: Unbox a => MutableByteArray a -> Int -> a -> IO ()
492pokeWith :: Unbox a => MutableByteArray a -> Int -> a -> IO ()
493−pokeWith = pokeByteIndex
493+pokeWith arr i = pokeByteIndex i arr
495--------------------------------------------------------------------------------
495--------------------------------------------------------------------------------
496-- Generic deriving
496-- Generic deriving
@@ -524,7 +524,7 @@ readUnsafe = Peeker (Builder step)
524 step :: forall a. Unbox a => BoundedPtr -> IO (BoundedPtr, a)
524 step :: forall a. Unbox a => BoundedPtr -> IO (BoundedPtr, a)
525 step (BoundedPtr arr pos end) = do
525 step (BoundedPtr arr pos end) = do
526 let next = pos + sizeOf (undefined :: a)
526 let next = pos + sizeOf (undefined :: a)
527− r <- peekByteIndex (castContents arr) pos
527+ r <- peekByteIndex pos (castContents arr)
528 return (BoundedPtr arr next end, r)
528 return (BoundedPtr arr next end, r)
530{-# INLINE read #-}
530{-# INLINE read #-}
@@ -538,7 +538,7 @@ read = Peeker (Builder step)
538 step (BoundedPtr arr pos end) = do
538 step (BoundedPtr arr pos end) = do
539 let next = pos + sizeOf (undefined :: a)
539 let next = pos + sizeOf (undefined :: a)
540 when (next > end) $ error "peekObject reading beyond limit"
540 when (next > end) $ error "peekObject reading beyond limit"
541− r <- peekByteIndex (castContents arr) pos
541+ r <- peekByteIndex pos (castContents arr)
542 return (BoundedPtr arr next end, r)
542 return (BoundedPtr arr next end, r)
544{-# INLINE skipByte #-}
544{-# INLINE skipByte #-}
@@ -572,7 +572,7 @@ runPeeker (Peeker (Builder f)) ptr = fmap snd (f ptr)
572pokeBoundedPtrUnsafe :: Unbox a => a -> BoundedPtr -> IO BoundedPtr
572pokeBoundedPtrUnsafe :: Unbox a => a -> BoundedPtr -> IO BoundedPtr
573pokeBoundedPtrUnsafe a (BoundedPtr arr pos end) = do
573pokeBoundedPtrUnsafe a (BoundedPtr arr pos end) = do
574 let next = pos + sizeOf a
574 let next = pos + sizeOf a
575− pokeByteIndex (castContents arr) pos a
575+ pokeByteIndex pos (castContents arr) a
576 return (BoundedPtr arr next end)
576 return (BoundedPtr arr next end)
578{-# INLINE pokeBoundedPtr #-}
578{-# INLINE pokeBoundedPtr #-}
@@ -580,7 +580,7 @@ pokeBoundedPtr :: Unbox a => a -> BoundedPtr -> IO BoundedPtr
580pokeBoundedPtr a (BoundedPtr arr pos end) = do
580pokeBoundedPtr a (BoundedPtr arr pos end) = do
581 let next = pos + sizeOf a
581 let next = pos + sizeOf a
582 when (next > end) $ error "pokeBoundedPtr writing beyond limit"
582 when (next > end) $ error "pokeBoundedPtr writing beyond limit"
583− pokeByteIndex (castContents arr) pos a
583+ pokeByteIndex pos (castContents arr) a
584 return (BoundedPtr arr next end)
584 return (BoundedPtr arr next end)
586--------------------------------------------------------------------------------
586--------------------------------------------------------------------------------