on master help sign in
Rename peekByteIndex/pokeByteIndex to peekAt/pokeAt
commit1efeed403bab200864232f2dc51d45b170c1593d authorHarendra Kumar <harendra@composewell.com> dateSat 25 Nov 2023, 11:43 (3 years ago) parent7cb856b
16 files changed+147−138
benchmark/Streamly/Benchmark/Data/Serialize.hs+2−2 core/src/Streamly/Internal/Data/Array.hs+3−3 core/src/Streamly/Internal/Data/Array/Type.hs+3−3 core/src/Streamly/Internal/Data/Fold/Chunked.hs+2−2 core/src/Streamly/Internal/Data/IORef/Unboxed.hs+3−3 core/src/Streamly/Internal/Data/MutArray/Type.hs+37−37 core/src/Streamly/Internal/Data/ParserK/Type.hs+1−1 core/src/Streamly/Internal/Data/Ring.hs+3−3 core/src/Streamly/Internal/Data/Serialize/TH/Bottom.hs+4−4 core/src/Streamly/Internal/Data/Serialize/TH/RecHeader.hs+2−2 core/src/Streamly/Internal/Data/Serialize/Type.hs+3−3 core/src/Streamly/Internal/Data/Unbox.hs+63−54 core/src/Streamly/Internal/Data/Unbox/TH.hs+8−8 core/src/Streamly/Internal/Unicode/Stream.hs+3−3 test/Streamly/Test/Data/Unbox.hs+8−8 test/Streamly/Test/Data/Unbox/TH.hs+2−2
benchmark/Streamly/Benchmark/Data/Serialize.hs+2−2
@@ -44,8 +44,8 @@ import Streamly.Benchmark.Data.Serialize.RecNonCompatible
4444#ifdef USE_UNBOX
4545#define SERIALIZE_CLASS Unbox
4646#define DERIVE_CLASS(typ) $(deriveUnbox [d|instance Unbox typ|])
47−#define SERIALIZE_OP pokeByteIndex
48−#define DESERIALIZE_OP peekByteIndex
47+#define SERIALIZE_OP pokeAt
48+#define DESERIALIZE_OP peekAt
4949#else
5050#define SERIALIZE_CLASS Serialize
5151#define DERIVE_CLASS(typ) $(deriveSerialize [d|instance Serialize typ|])
core/src/Streamly/Internal/Data/Array.hs+3−3
@@ -220,7 +220,7 @@ readerUnsafe = Unfold step inject
220220 --
221221 -- This should be safe as the array contents are guaranteed to be
222222 -- evaluated/written to before we peek at them.
223− let !x = unsafeInlineIO $ peekByteIndex p contents
223+ let !x = unsafeInlineIO $ peekAt p contents
224224 let !p1 = INDEX_NEXT(p,a)
225225 return $ D.Yield x (ArrayUnsafe contents end p1)
226226
@@ -243,7 +243,7 @@ getIndexRev i arr =
243243 $ do
244244 let elemPtr = RINDEX_OF(arrEnd arr, i, a)
245245 if i >= 0 && elemPtr >= arrStart arr
246− then Just <$> peekByteIndex elemPtr (arrContents arr)
246+ then Just <$> peekAt elemPtr (arrContents arr)
247247 else return Nothing
248248
249249-- |
@@ -404,7 +404,7 @@ getIndex i arr =
404404 $ do
405405 let elemPtr = INDEX_OF(arrStart arr, i, a)
406406 if i >= 0 && INDEX_VALID(elemPtr, arrEnd arr, a)
407− then Just <$> peekByteIndex elemPtr (arrContents arr)
407+ then Just <$> peekAt elemPtr (arrContents arr)
408408 else return Nothing
409409
410410-- | Given a stream of array indices, read the elements on those indices from
core/src/Streamly/Internal/Data/Array/Type.hs+3−3
@@ -501,8 +501,8 @@ toListFB c n Array{..} = go arrStart
501501 -- accumulating the list and fusing better with the pure consumers.
502502 --
503503 -- This should be safe as the array contents are guaranteed to be
504− -- evaluated/written to before we peekByteIndex at them.
505− let !x = unsafeInlineIO $ peekByteIndex p arrContents
504+ -- evaluated/written to before we peekAt at them.
505+ let !x = unsafeInlineIO $ peekAt p arrContents
506506 in c x (go (INDEX_NEXT(p,a)))
507507
508508-- | Convert an 'Array' into a list.
@@ -703,7 +703,7 @@ _toStreamD_ size Array{..} = D.Stream step arrStart
703703 {-# INLINE_LATE step #-}
704704 step _ p | p == arrEnd = return D.Stop
705705 step _ p = liftIO $ do
706− x <- peekByteIndex p arrContents
706+ x <- peekAt p arrContents
707707 return $ D.Yield x (p + size)
708708
709709{-
core/src/Streamly/Internal/Data/Fold/Chunked.hs+2−2
@@ -124,7 +124,7 @@ fromFold (Fold.Fold fstep finitial _ ffinal) =
124124 assert (cur == end) (return ())
125125 return $ Partial 0 fs
126126 goArray !_ !cur !fs = do
127− x <- liftIO $ peekByteIndex cur contents
127+ x <- liftIO $ peekAt cur contents
128128 res <- fstep fs x
129129 let elemSize = SIZE_OF(a)
130130 next = INDEX_NEXT(cur,a)
@@ -163,7 +163,7 @@ fromParserD (ParserD.Parser step1 initial1 extract1) =
163163 else return $ st (arrRem + n) fs1
164164
165165 goArray !_ !cur !fs = do
166− x <- liftIO $ peekByteIndex cur contents
166+ x <- liftIO $ peekAt cur contents
167167 res <- step1 fs x
168168 let elemSize = SIZE_OF(a)
169169 next = INDEX_NEXT(cur,a)
core/src/Streamly/Internal/Data/IORef/Unboxed.hs+3−3
@@ -56,7 +56,7 @@ newtype IORef a = IORef MutByteArray
5656newIORef :: forall a. Unbox a => a -> IO (IORef a)
5757newIORef x = do
5858 var <- MBA.new (sizeOf (Proxy :: Proxy a))
59− pokeByteIndex 0 var x
59+ pokeAt 0 var x
6060 return $ IORef var
6161
6262-- | Write a value to an 'IORef'.
@@ -64,14 +64,14 @@ newIORef x = do
6464-- /Pre-release/
6565{-# INLINE writeIORef #-}
6666writeIORef :: Unbox a => IORef a -> a -> IO ()
67−writeIORef (IORef var) = pokeByteIndex 0 var
67+writeIORef (IORef var) = pokeAt 0 var
6868
6969-- | Read a value from an 'IORef'.
7070--
7171-- /Pre-release/
7272{-# INLINE readIORef #-}
7373readIORef :: Unbox a => IORef a -> IO a
74−readIORef (IORef var) = peekByteIndex 0 var
74+readIORef (IORef var) = peekAt 0 var
7575
7676-- | Modify the value of an 'IORef' using a function with strict application.
7777--
core/src/Streamly/Internal/Data/MutArray/Type.hs+37−37
@@ -500,7 +500,7 @@ putIndexUnsafe :: forall m a. (MonadIO m, Unbox a)
500500putIndexUnsafe i MutArray{..} x = do
501501 let index = INDEX_OF(arrStart, i, a)
502502 assert (i >= 0 && INDEX_VALID(index, arrEnd, a)) (return ())
503− liftIO $ pokeByteIndex index arrContents x
503+ liftIO $ pokeAt index arrContents x
504504
505505invalidIndex :: String -> Int -> a
506506invalidIndex label i =
@@ -518,7 +518,7 @@ putIndex :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> a -> m ()
518518putIndex i MutArray{..} x = do
519519 let index = INDEX_OF(arrStart,i,a)
520520 if i >= 0 && INDEX_VALID(index,arrEnd,a)
521− then liftIO $ pokeByteIndex index arrContents x
521+ then liftIO $ pokeAt index arrContents x
522522 else invalidIndex "putIndex" i
523523
524524-- | Write an input stream of (index, value) pairs to an array. Throws an
@@ -544,9 +544,9 @@ modifyIndexUnsafe :: forall m a b. (MonadIO m, Unbox a) =>
544544modifyIndexUnsafe i MutArray{..} f = liftIO $ do
545545 let index = INDEX_OF(arrStart,i,a)
546546 assert (i >= 0 && INDEX_NEXT(index,a) <= arrEnd) (return ())
547− r <- peekByteIndex index arrContents
547+ r <- peekAt index arrContents
548548 let (x, res) = f r
549− pokeByteIndex index arrContents x
549+ pokeAt index arrContents x
550550 return res
551551
552552-- | Modify a given index of an array using a modifier function.
@@ -558,9 +558,9 @@ modifyIndex i MutArray{..} f = do
558558 let index = INDEX_OF(arrStart,i,a)
559559 if i >= 0 && INDEX_VALID(index,arrEnd,a)
560560 then liftIO $ do
561− r <- peekByteIndex index arrContents
561+ r <- peekAt index arrContents
562562 let (x, res) = f r
563− pokeByteIndex index arrContents x
563+ pokeAt index arrContents x
564564 return res
565565 else invalidIndex "modifyIndex" i
566566
@@ -594,8 +594,8 @@ modify MutArray{..} f = liftIO $
594594
595595 go i =
596596 when (INDEX_VALID(i,arrEnd,a)) $ do
597− r <- peekByteIndex i arrContents
598− pokeByteIndex i arrContents (f r)
597+ r <- peekAt i arrContents
598+ pokeAt i arrContents (f r)
599599 go (INDEX_NEXT(i,a))
600600
601601-- XXX We could specify the number of bytes to swap instead of Proxy. Need
@@ -609,10 +609,10 @@ swapArrayByteIndices ::
609609 -> Int
610610 -> IO ()
611611swapArrayByteIndices _ arrContents i1 i2 = do
612− r1 <- peekByteIndex i1 arrContents
613− r2 <- peekByteIndex i2 arrContents
614− pokeByteIndex i1 arrContents (r2 :: a)
615− pokeByteIndex i2 arrContents (r1 :: a)
612+ r1 <- peekAt i1 arrContents
613+ r2 <- peekAt i2 arrContents
614+ pokeAt i1 arrContents (r2 :: a)
615+ pokeAt i2 arrContents (r1 :: a)
616616
617617-- | Swap the elements at two indices without validating the indices.
618618--
@@ -889,7 +889,7 @@ rightSize arr@MutArray{..} = do
889889snocNewEnd :: (MonadIO m, Unbox a) => Int -> MutArray a -> a -> m (MutArray a)
890890snocNewEnd newEnd arr@MutArray{..} x = liftIO $ do
891891 assert (newEnd <= arrBound) (return ())
892− pokeByteIndex arrEnd arrContents x
892+ pokeAt arrEnd arrContents x
893893 return $ arr {arrEnd = newEnd}
894894
895895-- | Really really unsafe, appends the element into the first array, may
@@ -1003,7 +1003,7 @@ getIndexUnsafe :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m a
10031003getIndexUnsafe i MutArray{..} = do
10041004 let index = INDEX_OF(arrStart,i,a)
10051005 assert (i >= 0 && INDEX_VALID(index,arrEnd,a)) (return ())
1006− liftIO $ peekByteIndex index arrContents
1006+ liftIO $ peekAt index arrContents
10071007
10081008-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
10091009--
@@ -1012,7 +1012,7 @@ getIndex :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m (Maybe a)
10121012getIndex i MutArray{..} = do
10131013 let index = INDEX_OF(arrStart,i,a)
10141014 if i >= 0 && INDEX_VALID(index,arrEnd,a)
1015− then liftIO $ Just <$> peekByteIndex index arrContents
1015+ then liftIO $ Just <$> peekAt index arrContents
10161016 else return Nothing
10171017
10181018-- | /O(1)/ Lookup the element at the given index from the end of the array.
@@ -1025,7 +1025,7 @@ getIndexRev :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m a
10251025getIndexRev i MutArray{..} = do
10261026 let index = RINDEX_OF(arrEnd,i,a)
10271027 if i >= 0 && index >= arrStart
1028− then liftIO $ peekByteIndex index arrContents
1028+ then liftIO $ peekAt index arrContents
10291029 else invalidIndex "getIndexRev" i
10301030
10311031data GetIndicesState contents start end st =
@@ -1165,7 +1165,7 @@ partitionBy f arr@MutArray{..} = liftIO $ do
11651165
11661166 -- Invariant low < high on entry, and on return as well
11671167 moveHigh low high = do
1168− h <- peekByteIndex high arrContents
1168+ h <- peekAt high arrContents
11691169 if f h
11701170 then
11711171 -- Correctly classified, continue the loop
@@ -1185,7 +1185,7 @@ partitionBy f arr@MutArray{..} = liftIO $ do
11851185 -- low <= high
11861186 -- Both low and high are valid locations within the array
11871187 go low high = do
1188− l <- peekByteIndex low arrContents
1188+ l <- peekAt low arrContents
11891189 if f l
11901190 then
11911191 -- low is wrongly classified
@@ -1196,8 +1196,8 @@ partitionBy f arr@MutArray{..} = liftIO $ do
11961196 case r of
11971197 Nothing -> return low
11981198 Just (high1, h) -> do -- low < high1
1199− pokeByteIndex low arrContents h
1200− pokeByteIndex high1 arrContents l
1199+ pokeAt low arrContents h
1200+ pokeAt high1 arrContents l
12011201 let low1 = INDEX_NEXT(low,a)
12021202 high2 = INDEX_PREV(high1,a)
12031203 if low1 <= high2
@@ -1331,7 +1331,7 @@ chunksOfAs ps n (D.Stream step state) =
13311331 r <- step (adaptState gst) st
13321332 case r of
13331333 D.Yield x s -> do
1334− liftIO $ pokeByteIndex end contents x
1334+ liftIO $ pokeAt end contents x
13351335 let end1 = INDEX_NEXT(end,a)
13361336 return $
13371337 if end1 >= bound
@@ -1418,7 +1418,7 @@ flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
14181418 return $ D.Skip $ OuterLoop st
14191419
14201420 step' _ (InnerLoop st contents p end) = do
1421− x <- liftIO $ peekByteIndex p contents
1421+ x <- liftIO $ peekAt p contents
14221422 return $ D.Yield x (InnerLoop st contents (INDEX_NEXT(p,a)) end)
14231423
14241424-- | Use the "readerRev" unfold instead.
@@ -1448,7 +1448,7 @@ flattenArraysRev (D.Stream step state) = D.Stream step' (OuterLoop state)
14481448 return $ D.Skip $ OuterLoop st
14491449
14501450 step' _ (InnerLoop st contents p start) = do
1451− x <- liftIO $ peekByteIndex p contents
1451+ x <- liftIO $ peekAt p contents
14521452 let cur = INDEX_PREV(p,a)
14531453 return $ D.Yield x (InnerLoop st contents cur start)
14541454
@@ -1487,7 +1487,7 @@ producerWith liftio = Producer step (return . toArrayUnsafe) extract
14871487 -- few actions for correctness and execution order sanity. We want
14881488 -- the peek to occur right here and not lazily at some later point
14891489 -- because we want the peek to be ordered with respect to the touch.
1490− !x <- liftio $ peekByteIndex cur contents
1490+ !x <- liftio $ peekAt cur contents
14911491 return $ D.Yield x (ArrayUnsafe contents (INDEX_NEXT(cur,a)) end)
14921492
14931493 extract = return . fromArrayUnsafe
@@ -1518,7 +1518,7 @@ readerRevWith liftio = Unfold step inject
15181518 {-# INLINE_LATE step #-}
15191519 step (ArrayUnsafe _ start p) | p < start = return D.Stop
15201520 step (ArrayUnsafe contents start p) = do
1521− !x <- liftio $ peekByteIndex p contents
1521+ !x <- liftio $ peekAt p contents
15221522 return $ D.Yield x (ArrayUnsafe contents start (INDEX_PREV(p,a)))
15231523
15241524-- | Unfold an array into a stream in reverse order.
@@ -1549,7 +1549,7 @@ toListFB c n MutArray{..} = go arrStart
15491549 -- evaluated/written to before we peek at them.
15501550 -- XXX
15511551 let !x = unsafeInlineIO $ do
1552− r <- peekByteIndex arrContents p
1552+ r <- peekAt arrContents p
15531553 return r
15541554 in c x (go (PTR_NEXT(p,a)))
15551555-}
@@ -1566,7 +1566,7 @@ toList MutArray{..} = liftIO $ go arrStart
15661566
15671567 go p | assert (p <= arrEnd) (p == arrEnd) = return []
15681568 go p = do
1569− x <- peekByteIndex p arrContents
1569+ x <- peekAt p arrContents
15701570 (:) x <$> go (INDEX_NEXT(p,a))
15711571
15721572{-# INLINE_NORMAL toStreamDWith #-}
@@ -1580,7 +1580,7 @@ toStreamDWith liftio MutArray{..} = D.Stream step arrStart
15801580 {-# INLINE_LATE step #-}
15811581 step _ p | assert (p <= arrEnd) (p == arrEnd) = return D.Stop
15821582 step _ p = liftio $ do
1583− r <- peekByteIndex p arrContents
1583+ r <- peekAt p arrContents
15841584 return $ D.Yield r (INDEX_NEXT(p,a))
15851585
15861586-- | Convert a 'MutArray' into a stream.
@@ -1601,7 +1601,7 @@ toStreamKWith liftio MutArray{..} = go arrStart
16011601
16021602 go p | assert (p <= arrEnd) (p == arrEnd) = K.nil
16031603 | otherwise =
1604− let elemM = peekByteIndex p arrContents
1604+ let elemM = peekAt p arrContents
16051605 in liftio elemM `K.consM` go (INDEX_NEXT(p,a))
16061606
16071607{-# INLINE toStreamK #-}
@@ -1621,7 +1621,7 @@ toStreamDRevWith liftio MutArray{..} =
16211621 {-# INLINE_LATE step #-}
16221622 step _ p | p < arrStart = return D.Stop
16231623 step _ p = liftio $ do
1624− r <- peekByteIndex p arrContents
1624+ r <- peekAt p arrContents
16251625 return $ D.Yield r (INDEX_PREV(p,a))
16261626
16271627-- | Convert a 'MutArray' into a stream in reverse order.
@@ -1644,7 +1644,7 @@ toStreamKRevWith liftio MutArray {..} =
16441644
16451645 go p | p < arrStart = K.nil
16461646 | otherwise =
1647− let elemM = peekByteIndex p arrContents
1647+ let elemM = peekAt p arrContents
16481648 in liftio elemM `K.consM` go (INDEX_PREV(p,a))
16491649
16501650{-# INLINE toStreamKRev #-}
@@ -1712,7 +1712,7 @@ writeAppendNUnsafe n action =
17121712 return $ toArrayUnsafe arr1
17131713
17141714 step (ArrayUnsafe contents start end) x = do
1715− liftIO $ pokeByteIndex end contents x
1715+ liftIO $ pokeAt end contents x
17161716 return $ ArrayUnsafe contents start (INDEX_NEXT(end,a))
17171717
17181718-- | Append @n@ elements to an existing array. Any free space left in the array
@@ -1772,7 +1772,7 @@ writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
17721772 initial = toArrayUnsafe <$> alloc (max n 0)
17731773
17741774 step (ArrayUnsafe contents start end) x = do
1775− liftIO $ pokeByteIndex end contents x
1775+ liftIO $ pokeAt end contents x
17761776 return
17771777 $ ArrayUnsafe contents start (INDEX_NEXT(end,a))
17781778
@@ -1855,7 +1855,7 @@ writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
18551855
18561856 step (ArrayUnsafe contents start end) x = do
18571857 let ptr = INDEX_PREV(start,a)
1858− liftIO $ pokeByteIndex ptr contents x
1858+ liftIO $ pokeAt ptr contents x
18591859 return
18601860 $ ArrayUnsafe contents ptr end
18611861
@@ -1994,7 +1994,7 @@ fromStreamDNAs ps limit str = do
19941994 where
19951995
19961996 fwrite arrContents ptr x = do
1997− liftIO $ pokeByteIndex ptr arrContents x
1997+ liftIO $ pokeAt ptr arrContents x
19981998 return $ INDEX_NEXT(ptr,a)
19991999
20002000-- | Use the 'writeN' fold instead.
@@ -2416,7 +2416,7 @@ strip eq arr@MutArray{..} = liftIO $ do
24162416 getStart cur = do
24172417 if cur < arrEnd
24182418 then do
2419− r <- peekByteIndex cur arrContents
2419+ r <- peekAt cur arrContents
24202420 if eq r
24212421 then getStart (INDEX_NEXT(cur,a))
24222422 else return cur
@@ -2426,7 +2426,7 @@ strip eq arr@MutArray{..} = liftIO $ do
24262426 if cur > low
24272427 then do
24282428 let prev = INDEX_PREV(cur,a)
2429− r <- peekByteIndex prev arrContents
2429+ r <- peekAt prev arrContents
24302430 if eq r
24312431 then getLast prev low
24322432 else return cur
core/src/Streamly/Internal/Data/ParserK/Type.hs+1−1
@@ -404,7 +404,7 @@ adaptCWith pstep initial extract cont !offset0 !usedCount !input = do
404404 go !_ !cur !pst | cur >= end =
405405 onContinue ((end - start) `div` SIZE_OF(a)) pst
406406 go !_ !cur !pst = do
407− let !x = unsafeInlineIO $ peekByteIndex cur contents
407+ let !x = unsafeInlineIO $ peekAt cur contents
408408 pRes <- pstep pst x
409409 let elemSize = SIZE_OF(a)
410410 next = INDEX_NEXT(cur,a)
core/src/Streamly/Internal/Data/Ring.hs+3−3
@@ -79,7 +79,7 @@ import Foreign.Storable
7979import Foreign.ForeignPtr (ForeignPtr, withForeignPtr, touchForeignPtr)
8080import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
8181import Foreign.Ptr (plusPtr, minusPtr, castPtr)
82−import Streamly.Internal.Data.Unbox as Unboxed (Unbox(peekByteIndex))
82+import Streamly.Internal.Data.Unbox as Unboxed (Unbox(peekAt))
8383import GHC.ForeignPtr (mallocPlainForeignPtrAlignedBytes)
8484import GHC.Ptr (Ptr(..))
8585import Streamly.Internal.Data.MutArray.Type (MutArray)
@@ -411,7 +411,7 @@ unsafeEqArrayN Ring{..} rh A.Array{..} nBytes
411411
412412 check p i = do
413413 (relem :: Word8) <- peek p
414− aelem <- peekByteIndex i w8Contents
414+ aelem <- peekAt i w8Contents
415415 if relem == aelem
416416 then go (p `plusPtr` 1) (i + 1)
417417 else return False
@@ -445,7 +445,7 @@ unsafeEqArray Ring{..} rh A.Array{..} =
445445
446446 check p i = do
447447 (relem :: Word8) <- peek p
448− aelem <- peekByteIndex i w8Contents
448+ aelem <- peekAt i w8Contents
449449 if relem == aelem
450450 then go (p `plusPtr` 1) (i + 1)
451451 else return False
core/src/Streamly/Internal/Data/Serialize/TH/Bottom.hs+4−4
@@ -341,7 +341,7 @@ xorCmp tag off arr =
341341 go8 i = do
342342 let wIntegral = litIntegral i
343343 [|xor (unsafeInlineIO
344− (Unbox.peekByteIndex
344+ (Unbox.peekAt
345345 ($(varE off) + $(litIntegral i))
346346 $(varE arr)))
347347 ($(wIntegral) :: Word8) .|.
@@ -355,7 +355,7 @@ xorCmp tag off arr =
355355 litIntegral
356356 (shiftAdd w8_w16 [tag !! i, tag !! (i + 1)] :: Word16)
357357 [|xor (unsafeInlineIO
358− (Unbox.peekByteIndex
358+ (Unbox.peekAt
359359 ($(varE off) + $(litIntegral i))
360360 $(varE arr)))
361361 ($(wIntegral) :: Word16) .|.
@@ -375,7 +375,7 @@ xorCmp tag off arr =
375375 , tag !! (i + 3)
376376 ] :: Word32)
377377 [|xor (unsafeInlineIO
378− (Unbox.peekByteIndex
378+ (Unbox.peekAt
379379 ($(varE off) + $(litIntegral i))
380380 $(varE arr)))
381381 ($(wIntegral) :: Word32) .|.
@@ -399,7 +399,7 @@ xorCmp tag off arr =
399399 , tag !! (i + 7)
400400 ])
401401 [|xor (unsafeInlineIO
402− (Unbox.peekByteIndex
402+ (Unbox.peekAt
403403 ($(varE off) + $(litIntegral i))
404404 $(varE arr)))
405405 ($(wIntegral) :: Word64) .|.
core/src/Streamly/Internal/Data/Serialize/TH/RecHeader.hs+2−2
@@ -228,7 +228,7 @@ headerValue (SimpleDataCon _ fields) =
228228serializeWithSize :: Serialize a => Int -> MutByteArray -> a -> IO Int
229229serializeWithSize off arr val = do
230230 off1 <- serialize (off + 4) arr val
231− Unbox.pokeByteIndex off arr (int_w32 (off1 - off - 4) :: Word32)
231+ Unbox.pokeAt off arr (int_w32 (off1 - off - 4) :: Word32)
232232 pure off1
233233
234234mkRecSerializeExpr :: Name -> SimpleDataCon -> Q Exp
@@ -245,7 +245,7 @@ mkRecSerializeExpr initialOffset (con@(SimpleDataCon cname fields)) = do
245245 $(varP (makeI 0)) <- $(serializeW8List afterHLen _arr hval)
246246 let $(openConstructor cname (length fields)) = $(varE _val)
247247 finalOff <- $(mkSerializeExprFields 'serializeWithSize fields)
248− Unbox.pokeByteIndex
248+ Unbox.pokeAt
249249 $(varE initialOffset)
250250 $(varE _arr)
251251 ((fromIntegral :: Int -> Word32)
core/src/Streamly/Internal/Data/Serialize/Type.hs+3−3
@@ -189,7 +189,7 @@ deserializeUnsafe off arr sz =
189189 in do
190190 -- Keep likely path in the straight branch.
191191 if (next <= sz)
192− then Unbox.peekByteIndex off arr >>= \val -> pure (next, val)
192+ then Unbox.peekAt off arr >>= \val -> pure (next, val)
193193 else error
194194 $ "deserialize: accessing array at offset = "
195195 ++ show (next - 1)
@@ -203,7 +203,7 @@ serializeUnsafe off arr val =
203203#ifdef DEBUG
204204 checkBounds "serialize" next arr
205205#endif
206− Unbox.pokeByteIndex off arr val
206+ Unbox.pokeAt off arr val
207207 pure next
208208
209209#define DERIVE_SERIALIZE_FROM_UNBOX(_type) \
@@ -262,7 +262,7 @@ instance forall a. Serialize a => Serialize [a] where
262262 serialize off arr val = do
263263 let off1 = off + Unbox.sizeOf (Proxy :: Proxy Int64)
264264 let pokeList acc o [] =
265− Unbox.pokeByteIndex off arr (acc :: Int64) >> pure o
265+ Unbox.pokeAt off arr (acc :: Int64) >> pure o
266266 pokeList acc o (x:xs) = do
267267 o1 <- serialize o arr x
268268 pokeList (acc + 1) o1 xs
core/src/Streamly/Internal/Data/Unbox.hs+63−54
@@ -162,9 +162,9 @@ import Streamly.Internal.Data.MutByteArray.Type (MutByteArray(..))
162162-- have multiple constructors of different sizes, the size of a sum type is
163163-- computed as the maximum required by any constructor.
164164--
165−-- The 'peekByteIndex' operation reads as many bytes from the mutable byte
165+-- The 'peekAt' operation reads as many bytes from the mutable byte
166166-- array as the @size@ of the data type and builds a Haskell data type from
167−-- these bytes. 'pokeByteIndex' operation converts a Haskell data type to its
167+-- these bytes. 'pokeAt' operation converts a Haskell data type to its
168168-- binary representation which consists of @size@ bytes and then stores
169169-- these bytes into the mutable byte array. These operations do not check the
170170-- bounds of the array, the user of the type class is expected to check the
@@ -214,15 +214,15 @@ import Streamly.Internal.Data.MutByteArray.Type (MutByteArray(..))
214214-- >>> :{
215215-- instance Unbox Object where
216216-- sizeOf _ = 16
217−-- peekByteIndex i arr = do
217+-- peekAt i arr = do
218218-- -- Check the array bounds
219−-- x0 <- peekByteIndex i arr
220−-- x1 <- peekByteIndex (i + 8) arr
219+-- x0 <- peekAt i arr
220+-- x1 <- peekAt (i + 8) arr
221221-- return $ Object x0 x1
222−-- pokeByteIndex i arr (Object x0 x1) = do
222+-- pokeAt i arr (Object x0 x1) = do
223223-- -- Check the array bounds
224−-- pokeByteIndex i arr x0
225−-- pokeByteIndex (i + 8) arr x1
224+-- pokeAt i arr x0
225+-- pokeAt (i + 8) arr x1
226226-- :}
227227--
228228class Unbox a where
@@ -233,40 +233,49 @@ class Unbox a where
233233 default sizeOf :: (SizeOfRep (Rep a)) => Proxy a -> Int
234234 sizeOf = genericSizeOf
235235
236− -- | @peekByteIndex byte-index array@ reads an element of type @a@ from the
237− -- the given the byte index in the array.
236+ -- | @peekAt byte-offset array@ reads an element of type @a@ from the
237+ -- the given the byte offset in the array.
238238 --
239239 -- IMPORTANT: The implementation of this interface may not check the bounds
240240 -- of the array, the caller must not assume that.
241− peekByteIndex :: Int -> MutByteArray -> IO a
241+ peekAt :: Int -> MutByteArray -> IO a
242242
243− {-# INLINE peekByteIndex #-}
244− default peekByteIndex :: (Generic a, PeekRep (Rep a)) =>
243+ {-# INLINE peekAt #-}
244+ default peekAt :: (Generic a, PeekRep (Rep a)) =>
245245 Int -> MutByteArray -> IO a
246− peekByteIndex i arr = genericPeekByteIndex arr i
246+ peekAt i arr = genericPeekByteIndex arr i
247+
248+ peekByteIndex :: Int -> MutByteArray -> IO a
249+ peekByteIndex = peekAt
247250
248− -- | @pokeByteIndex byte-index array@ writes an element of type @a@ to the
249− -- the given the byte index in the array.
251+ -- | @pokeAt byte-offset array@ writes an element of type @a@ to the
252+ -- the given the byte offset in the array.
250253 --
251254 -- IMPORTANT: The implementation of this interface may not check the bounds
252255 -- of the array, the caller must not assume that.
256+ pokeAt :: Int -> MutByteArray -> a -> IO ()
257+
253258 pokeByteIndex :: Int -> MutByteArray -> a -> IO ()
259+ pokeByteIndex = pokeAt
254260
255− {-# INLINE pokeByteIndex #-}
256− default pokeByteIndex :: (Generic a, PokeRep (Rep a)) =>
261+ {-# INLINE pokeAt #-}
262+ default pokeAt :: (Generic a, PokeRep (Rep a)) =>
257263 Int -> MutByteArray -> a -> IO ()
258− pokeByteIndex i arr = genericPokeByteIndex arr i
264+ pokeAt i arr = genericPokeByteIndex arr i
265+
266+{-# DEPRECATED peekByteIndex "Use peekAt." #-}
267+{-# DEPRECATED pokeByteIndex "Use pokeAt." #-}
259268
260269-- XXX Add asserts to check bounds
261270
262271#define DERIVE_UNBOXED(_type, _constructor, _readArray, _writeArray, _sizeOf) \
263272instance Unbox _type where { \
264−; {-# INLINE peekByteIndex #-} \
265−; peekByteIndex (I# n) (MutByteArray mbarr) = IO $ \s -> \
273+; {-# INLINE peekAt #-} \
274+; peekAt (I# n) (MutByteArray mbarr) = IO $ \s -> \
266275 case _readArray mbarr n s of \
267276 { (# s1, i #) -> (# s1, _constructor i #) } \
268−; {-# INLINE pokeByteIndex #-} \
269−; pokeByteIndex (I# n) (MutByteArray mbarr) (_constructor val) = \
277+; {-# INLINE pokeAt #-} \
278+; pokeAt (I# n) (MutByteArray mbarr) (_constructor val) = \
270279 IO $ \s -> (# _writeArray mbarr n val s, () #) \
271280; {-# INLINE sizeOf #-} \
272281; sizeOf _ = _sizeOf \
@@ -274,24 +283,24 @@ instance Unbox _type where { \
274283
275284#define DERIVE_WRAPPED_UNBOX(_constraint, _type, _constructor, _innerType) \
276285instance _constraint Unbox _type where \
277−; {-# INLINE peekByteIndex #-} \
278−; peekByteIndex i arr = _constructor <$> peekByteIndex i arr \
279−; {-# INLINE pokeByteIndex #-} \
280−; pokeByteIndex i arr (_constructor a) = pokeByteIndex i arr a \
286+; {-# INLINE peekAt #-} \
287+; peekAt i arr = _constructor <$> peekAt i arr \
288+; {-# INLINE pokeAt #-} \
289+; pokeAt i arr (_constructor a) = pokeAt i arr a \
281290; {-# INLINE sizeOf #-} \
282291; sizeOf _ = SIZE_OF(_innerType)
283292
284293#define DERIVE_BINARY_UNBOX(_constraint, _type, _constructor, _innerType) \
285294instance _constraint Unbox _type where { \
286−; {-# INLINE peekByteIndex #-} \
287−; peekByteIndex i arr = \
288− peekByteIndex i arr >>= \
289− (\p1 -> peekByteIndex (i + SIZE_OF(_innerType)) arr \
295+; {-# INLINE peekAt #-} \
296+; peekAt i arr = \
297+ peekAt i arr >>= \
298+ (\p1 -> peekAt (i + SIZE_OF(_innerType)) arr \
290299 <&> _constructor p1) \
291−; {-# INLINE pokeByteIndex #-} \
292−; pokeByteIndex i arr (_constructor p1 p2) = \
293− pokeByteIndex i arr p1 >> \
294− pokeByteIndex (i + SIZE_OF(_innerType)) arr p2 \
300+; {-# INLINE pokeAt #-} \
301+; pokeAt i arr (_constructor p1 p2) = \
302+ pokeAt i arr p1 >> \
303+ pokeAt (i + SIZE_OF(_innerType)) arr p2 \
295304; {-# INLINE sizeOf #-} \
296305; sizeOf _ = 2 * SIZE_OF(_innerType) \
297306}
@@ -413,11 +422,11 @@ DERIVE_BINARY_UNBOX(,Fingerprint,Fingerprint,Word64)
413422
414423instance Unbox () where
415424
416− {-# INLINE peekByteIndex #-}
417− peekByteIndex _ _ = return ()
425+ {-# INLINE peekAt #-}
426+ peekAt _ _ = return ()
418427
419− {-# INLINE pokeByteIndex #-}
420− pokeByteIndex _ _ _ = return ()
428+ {-# INLINE pokeAt #-}
429+ pokeAt _ _ _ = return ()
421430
422431 {-# INLINE sizeOf #-}
423432 sizeOf _ = 1
@@ -425,11 +434,11 @@ instance Unbox () where
425434#if MIN_VERSION_base(4,15,0)
426435instance Unbox IoSubSystem where
427436
428− {-# INLINE peekByteIndex #-}
429− peekByteIndex i arr = toEnum <$> peekByteIndex i arr
437+ {-# INLINE peekAt #-}
438+ peekAt i arr = toEnum <$> peekAt i arr
430439
431− {-# INLINE pokeByteIndex #-}
432− pokeByteIndex i arr a = pokeByteIndex i arr (fromEnum a)
440+ {-# INLINE pokeAt #-}
441+ pokeAt i arr a = pokeAt i arr (fromEnum a)
433442
434443 {-# INLINE sizeOf #-}
435444 sizeOf _ = sizeOf (Proxy :: Proxy Int)
@@ -437,16 +446,16 @@ instance Unbox IoSubSystem where
437446
438447instance Unbox Bool where
439448
440− {-# INLINE peekByteIndex #-}
441− peekByteIndex i arr = do
442− res <- peekByteIndex i arr
449+ {-# INLINE peekAt #-}
450+ peekAt i arr = do
451+ res <- peekAt i arr
443452 return $ res /= (0 :: Int8)
444453
445− {-# INLINE pokeByteIndex #-}
446− pokeByteIndex i arr a =
454+ {-# INLINE pokeAt #-}
455+ pokeAt i arr a =
447456 if a
448− then pokeByteIndex i arr (1 :: Int8)
449− else pokeByteIndex i arr (0 :: Int8)
457+ then pokeAt i arr (1 :: Int8)
458+ else pokeAt i arr (0 :: Int8)
450459
451460 {-# INLINE sizeOf #-}
452461 sizeOf _ = 1
@@ -489,7 +498,7 @@ readUnsafe = Peeker (Builder step)
489498 ++ show next
490499 ++ " end = " ++ show end
491500#endif
492− r <- peekByteIndex pos arr
501+ r <- peekAt pos arr
493502 return (r, BoundedPtr arr next end)
494503
495504{-# INLINE read #-}
@@ -506,7 +515,7 @@ read = Peeker (Builder step)
506515 $ error $ "read: reading beyond limit. next = "
507516 ++ show next
508517 ++ " end = " ++ show end
509− r <- peekByteIndex pos arr
518+ r <- peekAt pos arr
510519 return (r, BoundedPtr arr next end)
511520
512521{-# INLINE skipByte #-}
@@ -551,7 +560,7 @@ pokeBoundedPtrUnsafe a (BoundedPtr arr pos end) = do
551560 ++ show next
552561 ++ " end = " ++ show end
553562#endif
554− pokeByteIndex pos arr a
563+ pokeAt pos arr a
555564 return (BoundedPtr arr next end)
556565
557566{-# INLINE pokeBoundedPtr #-}
@@ -559,7 +568,7 @@ pokeBoundedPtr :: forall a. Unbox a => a -> BoundedPtr -> IO BoundedPtr
559568pokeBoundedPtr a (BoundedPtr arr pos end) = do
560569 let next = pos + sizeOf (Proxy :: Proxy a)
561570 when (next > end) $ error "pokeBoundedPtr writing beyond limit"
562− pokeByteIndex pos arr a
571+ pokeAt pos arr a
563572 return (BoundedPtr arr next end)
564573
565574--------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/Unbox/TH.hs+8−8
@@ -252,7 +252,7 @@ mkPeekExprOne tagSize (DataCon cname _ _ fields) =
252252
253253 where
254254
255− peekField i = [|peekByteIndex $(varE (mkOffsetName i)) $(varE _arr)|]
255+ peekField i = [|peekAt $(varE (mkOffsetName i)) $(varE _arr)|]
256256
257257mkPeekExpr :: Type -> [DataCon] -> Q Exp
258258mkPeekExpr headTy cons =
@@ -266,7 +266,7 @@ mkPeekExpr headTy cons =
266266 doE
267267 [ bindS
268268 (varP _tag)
269− [|peekByteIndex $(varE _initialOffset) $(varE _arr)|]
269+ [|peekAt $(varE _initialOffset) $(varE _arr)|]
270270 , noBindS
271271 (caseE
272272 (sigE (varE _tag) (conT tagType))
@@ -299,7 +299,7 @@ mkPokeExprTag tagType tagVal = pokeTag
299299 where
300300
301301 pokeTag =
302− [|pokeByteIndex
302+ [|pokeAt
303303 $(varE _initialOffset)
304304 $(varE _arr)
305305 $((sigE (litE (IntegerL (fromIntegral tagVal))) (conT tagType)))|]
@@ -317,7 +317,7 @@ mkPokeExprFields tagSize fields = do
317317
318318 numFields = length fields
319319 pokeField i =
320− [|pokeByteIndex
320+ [|pokeAt
321321 $(varE (mkOffsetName i))
322322 $(varE _arr)
323323 $(varE (mkFieldName i))|]
@@ -402,9 +402,9 @@ deriveUnboxInternal headTy cons mkDec = do
402402 -- none
403403 [ -- PragmaD (InlineP 'sizeOf Inline FunLike AllPhases)
404404 FunD 'sizeOf [Clause [WildP] (NormalB sizeOfMethod) []]
405− , PragmaD (InlineP 'peekByteIndex Inline FunLike AllPhases)
405+ , PragmaD (InlineP 'peekAt Inline FunLike AllPhases)
406406 , FunD
407− 'peekByteIndex
407+ 'peekAt
408408 [ Clause
409409 (if isUnitType cons
410410 then [WildP, WildP]
@@ -412,9 +412,9 @@ deriveUnboxInternal headTy cons mkDec = do
412412 (NormalB peekMethod)
413413 []
414414 ]
415− , PragmaD (InlineP 'pokeByteIndex Inline FunLike AllPhases)
415+ , PragmaD (InlineP 'pokeAt Inline FunLike AllPhases)
416416 , FunD
417− 'pokeByteIndex
417+ 'pokeAt
418418 [ Clause
419419 (if isUnitType cons
420420 then [WildP, WildP, WildP]
core/src/Streamly/Internal/Unicode/Stream.hs+3−3
@@ -116,7 +116,7 @@ import Streamly.Internal.Data.Stream (Stream)
116116import Streamly.Internal.Data.Stream (Step (..))
117117import Streamly.Internal.Data.SVar.Type (adaptState)
118118import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
119−import Streamly.Internal.Data.Unbox (Unbox(peekByteIndex))
119+import Streamly.Internal.Data.Unbox (Unbox(peekAt))
120120import Streamly.Internal.Data.Unfold.Type (Unfold(..))
121121import Streamly.Internal.System.IO (unsafeInlineIO)
122122
@@ -746,7 +746,7 @@ decodeUtf8ArraysWithD cfm (D.Stream step state) =
746746 | p == end = do
747747 return $ Skip $ OuterLoop st Nothing
748748 step' _ _ (InnerLoopDecodeInit st contents p end) = do
749− x <- liftIO $ peekByteIndex p contents
749+ x <- liftIO $ peekAt p contents
750750 -- Note: It is important to use a ">" instead of a "<=" test here for
751751 -- GHC to generate code layout for default branch prediction for the
752752 -- common case. This is fragile and might change with the compiler
@@ -780,7 +780,7 @@ decodeUtf8ArraysWithD cfm (D.Stream step state) =
780780 step' _ _ (InnerLoopDecoding st _ p end sv cp)
781781 | p == end = return $ Skip $ OuterLoop st (Just (sv, cp))
782782 step' table _ (InnerLoopDecoding st contents p end statePtr codepointPtr) = do
783− x <- liftIO $ peekByteIndex p contents
783+ x <- liftIO $ peekAt p contents
784784 let (Tuple' sv cp) = decode1 table statePtr codepointPtr x
785785 return $
786786 case sv of
test/Streamly/Test/Data/Unbox.hs+8−8
@@ -46,8 +46,8 @@ import Test.Hspec as H
4646
4747#else
4848
49−#define PEEK(i, arr, sz) peekByteIndexWithNextOff i arr
50−#define POKE(i, arr, val) pokeByteIndexWithNextOff i arr val
49+#define PEEK(i, arr, sz) peekAtWithNextOff i arr
50+#define POKE(i, arr, val) pokeAtWithNextOff i arr val
5151#define TYPE_CLASS Unbox
5252
5353#ifdef USE_TH
@@ -70,23 +70,23 @@ import Test.Hspec as H
7070
7171#ifndef USE_SERIALIZE
7272
73−peekByteIndexWithNextOff ::
73+peekAtWithNextOff ::
7474 forall a. Unbox a
7575 => Int
7676 -> MutByteArray
7777 -> IO (Int, a)
78−peekByteIndexWithNextOff i arr = do
79− val <- peekByteIndex i arr
78+peekAtWithNextOff i arr = do
79+ val <- peekAt i arr
8080 pure (i + sizeOf (Proxy :: Proxy a), val)
8181
82−pokeByteIndexWithNextOff ::
82+pokeAtWithNextOff ::
8383 forall a. Unbox a
8484 => Int
8585 -> MutByteArray
8686 -> a
8787 -> IO Int
88−pokeByteIndexWithNextOff i arr val = do
89− pokeByteIndex i arr val
88+pokeAtWithNextOff i arr val = do
89+ pokeAt i arr val
9090 pure $ i + sizeOf (Proxy :: Proxy a)
9191
9292#endif
test/Streamly/Test/Data/Unbox/TH.hs+2−2
@@ -30,8 +30,8 @@ testSerialization ::
3030 -> IO ()
3131testSerialization val = do
3232 arr <- MBA.new (sizeOf (Proxy :: Proxy a))
33− pokeByteIndex 0 arr val
34− peekByteIndex 0 arr `shouldReturn` val
33+ pokeAt 0 arr val
34+ peekAt 0 arr `shouldReturn` val
3535
3636-- Size is also implicitly tested while serializing and deserializing.
3737checkSizeOf :: forall a. Unbox a => Proxy a -> Int -> IO ()