on master help sign in
Remove peekWith and pokeWith helper functions in Unbox
commiteee265456e7f7c595d59ed71ffb824f1e1cb273b authorAdithya Kumar <adithya@composewell.com> dateTue 25 Jul 2023, 01:02 (3 years ago) parent39b2790
10 files changed+69−92
core/src/Streamly/Internal/Data/Array.hs+4−8 core/src/Streamly/Internal/Data/Array/Mut/Type.hs+38−41 core/src/Streamly/Internal/Data/Array/Type.hs+4−4 core/src/Streamly/Internal/Data/Fold/Chunked.hs+3−3 core/src/Streamly/Internal/Data/IORef/Unboxed.hs+5−7 core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+2−2 core/src/Streamly/Internal/Data/Ring/Unboxed.hs+3−3 core/src/Streamly/Internal/Data/Stream/Chunked.hs+7−7 core/src/Streamly/Internal/Data/Unbox.hs−14 core/src/Streamly/Internal/Unicode/Stream.hs+3−3
core/src/Streamly/Internal/Data/Array.hs+4−8
@@ -114,11 +114,7 @@ import Data.Word (Word8)
114114import Foreign.C.String (CString)
115115import Foreign.Ptr (castPtr)
116116import Foreign.Storable (Storable)
117−import Streamly.Internal.Data.Unbox
118− ( Unbox
119− , peekWith
120− , sizeOf
121− )
117+import Streamly.Internal.Data.Unbox (Unbox(..))
122118import Prelude hiding (length, null, last, map, (!!), read, concat)
123119
124120import Streamly.Internal.Data.Array.Mut.Type (ArrayUnsafe(..))
@@ -239,7 +235,7 @@ readerUnsafe = Unfold step inject
239235 --
240236 -- This should be safe as the array contents are guaranteed to be
241237 -- evaluated/written to before we peek at them.
242− let !x = unsafeInlineIO $ peekWith contents p
238+ let !x = unsafeInlineIO $ peekByteIndex p contents
243239 let !p1 = INDEX_NEXT(p,a)
244240 return $ D.Yield x (ArrayUnsafe contents end p1)
245241
@@ -263,7 +259,7 @@ getIndexRev i arr =
263259 $ do
264260 let elemPtr = RINDEX_OF(arrEnd arr, i, a)
265261 if i >= 0 && elemPtr >= arrStart arr
266− then Just <$> peekWith (arrContents arr) elemPtr
262+ then Just <$> peekByteIndex elemPtr (arrContents arr)
267263 else return Nothing
268264
269265-- |
@@ -425,7 +421,7 @@ getIndex i arr =
425421 $ do
426422 let elemPtr = INDEX_OF(arrStart arr, i, a)
427423 if i >= 0 && INDEX_VALID(elemPtr, arrEnd arr, a)
428− then Just <$> peekWith (arrContents arr) elemPtr
424+ then Just <$> peekByteIndex elemPtr (arrContents arr)
429425 else return Nothing
430426
431427-- | Given a stream of array indices, read the elements on those indices from
core/src/Streamly/Internal/Data/Array/Mut/Type.hs+38−41
@@ -235,11 +235,8 @@ import Foreign.C.Types (CSize(..), CInt(..))
235235import Foreign.Ptr (plusPtr, minusPtr, nullPtr)
236236import Streamly.Internal.Data.Unbox
237237 ( MutableByteArray(..)
238− , Unbox
238+ , Unbox(..)
239239 , getMutableByteArray#
240− , peekWith
241− , pokeWith
242− , sizeOf
243240 , touch
244241 )
245242import GHC.Base
@@ -497,7 +494,7 @@ putIndexUnsafe :: forall m a. (MonadIO m, Unbox a)
497494putIndexUnsafe i MutArray{..} x = do
498495 let index = INDEX_OF(arrStart, i, a)
499496 assert (i >= 0 && INDEX_VALID(index, arrEnd, a)) (return ())
500− liftIO $ pokeWith arrContents index x
497+ liftIO $ pokeByteIndex index arrContents x
501498
502499invalidIndex :: String -> Int -> a
503500invalidIndex label i =
@@ -515,7 +512,7 @@ putIndex :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> a -> m ()
515512putIndex i MutArray{..} x = do
516513 let index = INDEX_OF(arrStart,i,a)
517514 if i >= 0 && INDEX_VALID(index,arrEnd,a)
518− then liftIO $ pokeWith arrContents index x
515+ then liftIO $ pokeByteIndex index arrContents x
519516 else invalidIndex "putIndex" i
520517
521518-- | Write an input stream of (index, value) pairs to an array. Throws an
@@ -541,9 +538,9 @@ modifyIndexUnsafe :: forall m a b. (MonadIO m, Unbox a) =>
541538modifyIndexUnsafe i MutArray{..} f = liftIO $ do
542539 let index = INDEX_OF(arrStart,i,a)
543540 assert (i >= 0 && INDEX_NEXT(index,a) <= arrEnd) (return ())
544− r <- peekWith arrContents index
541+ r <- peekByteIndex index arrContents
545542 let (x, res) = f r
546− pokeWith arrContents index x
543+ pokeByteIndex index arrContents x
547544 return res
548545
549546-- | Modify a given index of an array using a modifier function.
@@ -555,9 +552,9 @@ modifyIndex i MutArray{..} f = do
555552 let index = INDEX_OF(arrStart,i,a)
556553 if i >= 0 && INDEX_VALID(index,arrEnd,a)
557554 then liftIO $ do
558− r <- peekWith arrContents index
555+ r <- peekByteIndex index arrContents
559556 let (x, res) = f r
560− pokeWith arrContents index x
557+ pokeByteIndex index arrContents x
561558 return res
562559 else invalidIndex "modifyIndex" i
563560
@@ -591,8 +588,8 @@ modify MutArray{..} f = liftIO $
591588
592589 go i =
593590 when (INDEX_VALID(i,arrEnd,a)) $ do
594− r <- peekWith arrContents i
595− pokeWith arrContents i (f r)
591+ r <- peekByteIndex i arrContents
592+ pokeByteIndex i arrContents (f r)
596593 go (INDEX_NEXT(i,a))
597594
598595-- XXX We could specify the number of bytes to swap instead of Proxy. Need
@@ -606,10 +603,10 @@ swapArrayByteIndices ::
606603 -> Int
607604 -> IO ()
608605swapArrayByteIndices _ arrContents i1 i2 = do
609− r1 <- peekWith arrContents i1
610− r2 <- peekWith arrContents i2
611− pokeWith arrContents i1 (r2 :: a)
612− pokeWith arrContents i2 (r1 :: a)
606+ r1 <- peekByteIndex i1 arrContents
607+ r2 <- peekByteIndex i2 arrContents
608+ pokeByteIndex i1 arrContents (r2 :: a)
609+ pokeByteIndex i2 arrContents (r1 :: a)
613610
614611-- | Swap the elements at two indices without validating the indices.
615612--
@@ -882,7 +879,7 @@ rightSize arr@MutArray{..} = do
882879snocNewEnd :: (MonadIO m, Unbox a) => Int -> MutArray a -> a -> m (MutArray a)
883880snocNewEnd newEnd arr@MutArray{..} x = liftIO $ do
884881 assert (newEnd <= arrBound) (return ())
885− pokeWith arrContents arrEnd x
882+ pokeByteIndex arrEnd arrContents x
886883 return $ arr {arrEnd = newEnd}
887884
888885-- | Really really unsafe, appends the element into the first array, may
@@ -996,7 +993,7 @@ getIndexUnsafe :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m a
996993getIndexUnsafe i MutArray{..} = do
997994 let index = INDEX_OF(arrStart,i,a)
998995 assert (i >= 0 && INDEX_VALID(index,arrEnd,a)) (return ())
999− liftIO $ peekWith arrContents index
996+ liftIO $ peekByteIndex index arrContents
1000997
1001998-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
1002999--
@@ -1005,7 +1002,7 @@ getIndex :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m (Maybe a)
10051002getIndex i MutArray{..} = do
10061003 let index = INDEX_OF(arrStart,i,a)
10071004 if i >= 0 && INDEX_VALID(index,arrEnd,a)
1008− then liftIO $ Just <$> peekWith arrContents index
1005+ then liftIO $ Just <$> peekByteIndex index arrContents
10091006 else return Nothing
10101007
10111008-- | /O(1)/ Lookup the element at the given index from the end of the array.
@@ -1018,7 +1015,7 @@ getIndexRev :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m a
10181015getIndexRev i MutArray{..} = do
10191016 let index = RINDEX_OF(arrEnd,i,a)
10201017 if i >= 0 && index >= arrStart
1021− then liftIO $ peekWith arrContents index
1018+ then liftIO $ peekByteIndex index arrContents
10221019 else invalidIndex "getIndexRev" i
10231020
10241021data GetIndicesState contents start end st =
@@ -1158,7 +1155,7 @@ partitionBy f arr@MutArray{..} = liftIO $ do
11581155
11591156 -- Invariant low < high on entry, and on return as well
11601157 moveHigh low high = do
1161− h <- peekWith arrContents high
1158+ h <- peekByteIndex high arrContents
11621159 if f h
11631160 then
11641161 -- Correctly classified, continue the loop
@@ -1178,7 +1175,7 @@ partitionBy f arr@MutArray{..} = liftIO $ do
11781175 -- low <= high
11791176 -- Both low and high are valid locations within the array
11801177 go low high = do
1181− l <- peekWith arrContents low
1178+ l <- peekByteIndex low arrContents
11821179 if f l
11831180 then
11841181 -- low is wrongly classified
@@ -1189,8 +1186,8 @@ partitionBy f arr@MutArray{..} = liftIO $ do
11891186 case r of
11901187 Nothing -> return low
11911188 Just (high1, h) -> do -- low < high1
1192− pokeWith arrContents low h
1193− pokeWith arrContents high1 l
1189+ pokeByteIndex low arrContents h
1190+ pokeByteIndex high1 arrContents l
11941191 let low1 = INDEX_NEXT(low,a)
11951192 high2 = INDEX_PREV(high1,a)
11961193 if low1 <= high2
@@ -1334,7 +1331,7 @@ chunksOf n (D.Stream step state) =
13341331 r <- step (adaptState gst) st
13351332 case r of
13361333 D.Yield x s -> do
1337− liftIO $ pokeWith contents end x
1334+ liftIO $ pokeByteIndex end contents x
13381335 let end1 = INDEX_NEXT(end,a)
13391336 return $
13401337 if end1 >= bound
@@ -1396,7 +1393,7 @@ flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
13961393 return $ D.Skip $ OuterLoop st
13971394
13981395 step' _ (InnerLoop st contents p end) = do
1399− x <- liftIO $ peekWith contents p
1396+ x <- liftIO $ peekByteIndex p contents
14001397 return $ D.Yield x (InnerLoop st contents (INDEX_NEXT(p,a)) end)
14011398
14021399-- | Use the "readerRev" unfold instead.
@@ -1426,7 +1423,7 @@ flattenArraysRev (D.Stream step state) = D.Stream step' (OuterLoop state)
14261423 return $ D.Skip $ OuterLoop st
14271424
14281425 step' _ (InnerLoop st contents p start) = do
1429− x <- liftIO $ peekWith contents p
1426+ x <- liftIO $ peekByteIndex p contents
14301427 let cur = INDEX_PREV(p,a)
14311428 return $ D.Yield x (InnerLoop st contents cur start)
14321429
@@ -1465,7 +1462,7 @@ producerWith liftio = Producer step (return . toArrayUnsafe) extract
14651462 -- few actions for correctness and execution order sanity. We want
14661463 -- the peek to occur right here and not lazily at some later point
14671464 -- because we want the peek to be ordered with respect to the touch.
1468− !x <- liftio $ peekWith contents cur
1465+ !x <- liftio $ peekByteIndex cur contents
14691466 return $ D.Yield x (ArrayUnsafe contents (INDEX_NEXT(cur,a)) end)
14701467
14711468 extract = return . fromArrayUnsafe
@@ -1496,7 +1493,7 @@ readerRevWith liftio = Unfold step inject
14961493 {-# INLINE_LATE step #-}
14971494 step (ArrayUnsafe _ start p) | p < start = return D.Stop
14981495 step (ArrayUnsafe contents start p) = do
1499− !x <- liftio $ peekWith contents p
1496+ !x <- liftio $ peekByteIndex p contents
15001497 return $ D.Yield x (ArrayUnsafe contents start (INDEX_PREV(p,a)))
15011498
15021499-- | Unfold an array into a stream in reverse order.
@@ -1527,7 +1524,7 @@ toListFB c n MutArray{..} = go arrStart
15271524 -- evaluated/written to before we peek at them.
15281525 -- XXX
15291526 let !x = unsafeInlineIO $ do
1530− r <- peekWith arrContents p
1527+ r <- peekByteIndex arrContents p
15311528 return r
15321529 in c x (go (PTR_NEXT(p,a)))
15331530-}
@@ -1544,7 +1541,7 @@ toList MutArray{..} = liftIO $ go arrStart
15441541
15451542 go p | assert (p <= arrEnd) (p == arrEnd) = return []
15461543 go p = do
1547− x <- peekWith arrContents p
1544+ x <- peekByteIndex p arrContents
15481545 (:) x <$> go (INDEX_NEXT(p,a))
15491546
15501547{-# INLINE_NORMAL toStreamDWith #-}
@@ -1558,7 +1555,7 @@ toStreamDWith liftio MutArray{..} = D.Stream step arrStart
15581555 {-# INLINE_LATE step #-}
15591556 step _ p | assert (p <= arrEnd) (p == arrEnd) = return D.Stop
15601557 step _ p = liftio $ do
1561− r <- peekWith arrContents p
1558+ r <- peekByteIndex p arrContents
15621559 return $ D.Yield r (INDEX_NEXT(p,a))
15631560
15641561-- | Convert a 'MutArray' into a stream.
@@ -1579,7 +1576,7 @@ toStreamKWith liftio MutArray{..} = go arrStart
15791576
15801577 go p | assert (p <= arrEnd) (p == arrEnd) = K.nil
15811578 | otherwise =
1582− let elemM = peekWith arrContents p
1579+ let elemM = peekByteIndex p arrContents
15831580 in liftio elemM `K.consM` go (INDEX_NEXT(p,a))
15841581
15851582{-# INLINE toStreamK #-}
@@ -1599,7 +1596,7 @@ toStreamDRevWith liftio MutArray{..} =
15991596 {-# INLINE_LATE step #-}
16001597 step _ p | p < arrStart = return D.Stop
16011598 step _ p = liftio $ do
1602− r <- peekWith arrContents p
1599+ r <- peekByteIndex p arrContents
16031600 return $ D.Yield r (INDEX_PREV(p,a))
16041601
16051602-- | Convert a 'MutArray' into a stream in reverse order.
@@ -1622,7 +1619,7 @@ toStreamKRevWith liftio MutArray {..} =
16221619
16231620 go p | p < arrStart = K.nil
16241621 | otherwise =
1625− let elemM = peekWith arrContents p
1622+ let elemM = peekByteIndex p arrContents
16261623 in liftio elemM `K.consM` go (INDEX_PREV(p,a))
16271624
16281625{-# INLINE toStreamKRev #-}
@@ -1690,7 +1687,7 @@ writeAppendNUnsafe n action =
16901687 return $ toArrayUnsafe arr1
16911688
16921689 step (ArrayUnsafe contents start end) x = do
1693− liftIO $ pokeWith contents end x
1690+ liftIO $ pokeByteIndex end contents x
16941691 return $ ArrayUnsafe contents start (INDEX_NEXT(end,a))
16951692
16961693-- | Append @n@ elements to an existing array. Any free space left in the array
@@ -1750,7 +1747,7 @@ writeNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
17501747 initial = toArrayUnsafe <$> alloc (max n 0)
17511748
17521749 step (ArrayUnsafe contents start end) x = do
1753− liftIO $ pokeWith contents end x
1750+ liftIO $ pokeByteIndex end contents x
17541751 return
17551752 $ ArrayUnsafe contents start (INDEX_NEXT(end,a))
17561753
@@ -1806,7 +1803,7 @@ writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
18061803
18071804 step (ArrayUnsafe contents start end) x = do
18081805 let ptr = INDEX_PREV(start,a)
1809− liftIO $ pokeWith contents ptr x
1806+ liftIO $ pokeByteIndex ptr contents x
18101807 return
18111808 $ ArrayUnsafe contents ptr end
18121809
@@ -1938,7 +1935,7 @@ fromStreamDN limit str = do
19381935 where
19391936
19401937 fwrite arrContents ptr x = do
1941− liftIO $ pokeWith arrContents ptr x
1938+ liftIO $ pokeByteIndex ptr arrContents x
19421939 return $ INDEX_NEXT(ptr,a)
19431940
19441941-- | Create a 'MutArray' from the first N elements of a list. The array is
@@ -2328,7 +2325,7 @@ strip eq arr@MutArray{..} = liftIO $ do
23282325 getStart cur = do
23292326 if cur < arrEnd
23302327 then do
2331− r <- peekWith arrContents cur
2328+ r <- peekByteIndex cur arrContents
23322329 if eq r
23332330 then getStart (INDEX_NEXT(cur,a))
23342331 else return cur
@@ -2338,7 +2335,7 @@ strip eq arr@MutArray{..} = liftIO $ do
23382335 if cur > low
23392336 then do
23402337 let prev = INDEX_PREV(cur,a)
2341− r <- peekWith arrContents prev
2338+ r <- peekByteIndex prev arrContents
23422339 if eq r
23432340 then getLast prev low
23442341 else return cur
core/src/Streamly/Internal/Data/Array/Type.hs+4−4
@@ -95,7 +95,7 @@ import GHC.Ptr (Ptr(..))
9595import Streamly.Internal.Data.Array.Mut.Type (MutArray(..), MutableByteArray)
9696import Streamly.Internal.Data.Fold.Type (Fold(..))
9797import Streamly.Internal.Data.Stream.StreamD.Type (Stream)
98−import Streamly.Internal.Data.Unbox (Unbox, peekWith, sizeOf)
98+import Streamly.Internal.Data.Unbox (Unbox(..))
9999import Streamly.Internal.Data.Unfold.Type (Unfold(..))
100100import Text.Read (readPrec)
101101
@@ -447,8 +447,8 @@ toListFB c n Array{..} = go arrStart
447447 -- accumulating the list and fusing better with the pure consumers.
448448 --
449449 -- This should be safe as the array contents are guaranteed to be
450− -- evaluated/written to before we peekWith at them.
451− let !x = unsafeInlineIO $ peekWith arrContents p
450+ -- evaluated/written to before we peekByteIndex at them.
451+ let !x = unsafeInlineIO $ peekByteIndex p arrContents
452452 in c x (go (INDEX_NEXT(p,a)))
453453
454454-- | Convert an 'Array' into a list.
@@ -636,7 +636,7 @@ _toStreamD_ size Array{..} = D.Stream step arrStart
636636 {-# INLINE_LATE step #-}
637637 step _ p | p == arrEnd = return D.Stop
638638 step _ p = liftIO $ do
639− x <- peekWith arrContents p
639+ x <- peekByteIndex p arrContents
640640 return $ D.Yield x (p + size)
641641
642642{-
core/src/Streamly/Internal/Data/Fold/Chunked.hs+3−3
@@ -63,7 +63,7 @@ import Control.Exception (assert)
6363import Control.Monad.IO.Class (MonadIO(..))
6464import Data.Bifunctor (first)
6565import Data.Proxy (Proxy(..))
66−import Streamly.Internal.Data.Unbox (peekWith, sizeOf, Unbox)
66+import Streamly.Internal.Data.Unbox (Unbox(..))
6767import GHC.Types (SPEC(..))
6868import Streamly.Internal.Data.Array.Mut.Type (touch)
6969import Streamly.Internal.Data.Array.Type (Array(..))
@@ -123,7 +123,7 @@ fromFold (Fold.Fold fstep finitial fextract) =
123123 assert (cur == end) (return ())
124124 return $ Partial 0 fs
125125 goArray !_ !cur !fs = do
126− x <- liftIO $ peekWith contents cur
126+ x <- liftIO $ peekByteIndex cur contents
127127 res <- fstep fs x
128128 let elemSize = SIZE_OF(a)
129129 next = INDEX_NEXT(cur,a)
@@ -160,7 +160,7 @@ fromParserD (ParserD.Parser step1 initial1 extract1) =
160160 else return $ st (arrRem + n) fs1
161161
162162 goArray !_ !cur !fs = do
163− x <- liftIO $ peekWith contents cur
163+ x <- liftIO $ peekByteIndex cur contents
164164 liftIO $ touch contents
165165 res <- step1 fs x
166166 let elemSize = SIZE_OF(a)
core/src/Streamly/Internal/Data/IORef/Unboxed.hs+5−7
@@ -42,11 +42,9 @@ import Data.Proxy (Proxy(..))
4242import Control.Monad.IO.Class (MonadIO(..))
4343import Streamly.Internal.Data.Unbox
4444 ( MutableByteArray(..)
45− , Unbox
46− , sizeOf
47− , peekWith
48− , pokeWith
45+ , Unbox(..)
4946 , newUnpinnedBytes
47+ , sizeOf
5048 )
5149
5250import qualified Streamly.Internal.Data.Stream.StreamD.Type as D
@@ -61,7 +59,7 @@ newtype IORef a = IORef MutableByteArray
6159newIORef :: forall a. Unbox a => a -> IO (IORef a)
6260newIORef x = do
6361 var <- newUnpinnedBytes (sizeOf (Proxy :: Proxy a))
64− pokeWith var 0 x
62+ pokeByteIndex 0 var x
6563 return $ IORef var
6664
6765-- | Write a value to an 'IORef'.
@@ -69,14 +67,14 @@ newIORef x = do
6967-- /Pre-release/
7068{-# INLINE writeIORef #-}
7169writeIORef :: Unbox a => IORef a -> a -> IO ()
72−writeIORef (IORef var) = pokeWith var 0
70+writeIORef (IORef var) = pokeByteIndex 0 var
7371
7472-- | Read a value from an 'IORef'.
7573--
7674-- /Pre-release/
7775{-# INLINE readIORef #-}
7876readIORef :: Unbox a => IORef a -> IO a
79−readIORef (IORef var) = peekWith var 0
77+readIORef (IORef var) = peekByteIndex 0 var
8078
8179-- | Modify the value of an 'IORef' using a function with strict application.
8280--
core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+2−2
@@ -46,7 +46,7 @@ import Control.Monad.IO.Class (MonadIO, liftIO)
4646import Data.Proxy (Proxy(..))
4747import GHC.Types (SPEC(..))
4848import Streamly.Internal.Data.Array.Type (Array(..))
49−import Streamly.Internal.Data.Unbox (peekWith, sizeOf, Unbox)
49+import Streamly.Internal.Data.Unbox (Unbox(..))
5050import Streamly.Internal.System.IO (unsafeInlineIO)
5151
5252import qualified Control.Monad.Fail as Fail
@@ -430,7 +430,7 @@ parseDToK pstep initial extract cont !offset0 !usedCount !input = do
430430 go !_ !cur !pst | cur >= end =
431431 onContinue ((end - start) `div` SIZE_OF(a)) pst
432432 go !_ !cur !pst = do
433− let !x = unsafeInlineIO $ peekWith contents cur
433+ let !x = unsafeInlineIO $ peekByteIndex cur contents
434434 pRes <- pstep pst x
435435 let elemSize = SIZE_OF(a)
436436 next = INDEX_NEXT(cur,a)
core/src/Streamly/Internal/Data/Ring/Unboxed.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, peekWith)
82+import Streamly.Internal.Data.Unbox as Unboxed (Unbox(peekByteIndex))
8383import GHC.ForeignPtr (mallocPlainForeignPtrAlignedBytes)
8484import GHC.Ptr (Ptr(..))
8585import Streamly.Internal.Data.Array.Mut.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 <- peekWith w8Contents i
414+ aelem <- peekByteIndex 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 <- peekWith w8Contents i
448+ aelem <- peekByteIndex i w8Contents
449449 if relem == aelem
450450 then go (p `plusPtr` 1) (i + 1)
451451 else return False
core/src/Streamly/Internal/Data/Stream/Chunked.hs+7−7
@@ -69,7 +69,7 @@ import Control.Exception (assert)
6969import Control.Monad.IO.Class (MonadIO(..))
7070import Data.Proxy (Proxy(..))
7171import Data.Word (Word8)
72−import Streamly.Internal.Data.Unbox (Unbox, peekWith, sizeOf)
72+import Streamly.Internal.Data.Unbox (Unbox(..))
7373import Fusion.Plugin.Types (Fuse(..))
7474import GHC.Exts (SpecConstrAnnotation(..))
7575import GHC.Types (SPEC(..))
@@ -201,7 +201,7 @@ unlines sep (D.Stream step state) = D.Stream step' (OuterLoop state)
201201 return $ D.Yield sep $ OuterLoop st
202202
203203 step' _ (InnerLoop st contents p end) = do
204− x <- liftIO $ peekWith contents p
204+ x <- liftIO $ peekByteIndex p contents
205205 return $ D.Yield x (InnerLoop st contents (INDEX_NEXT(p,a)) end)
206206
207207-------------------------------------------------------------------------------
@@ -355,7 +355,7 @@ foldBreakD (FL.Fold fstep initial extract) stream@(D.Stream step state) = do
355355 | cur == end = do
356356 go SPEC s fs
357357 goArray !_ st fp@(Tuple' end contents) !cur !fs = do
358− x <- liftIO $ peekWith contents cur
358+ x <- liftIO $ peekByteIndex cur contents
359359 res <- fstep fs x
360360 let next = INDEX_NEXT(cur,a)
361361 case res of
@@ -388,7 +388,7 @@ foldBreakK (FL.Fold fstep initial extract) stream = do
388388 | cur == end = do
389389 go fs st
390390 goArray !fs st fp@(Tuple' end contents) !cur = do
391− x <- liftIO $ peekWith contents cur
391+ x <- liftIO $ peekByteIndex cur contents
392392 res <- fstep fs x
393393 let next = INDEX_NEXT(cur,a)
394394 case res of
@@ -597,7 +597,7 @@ parseBreakD
597597 | cur == end = do
598598 go SPEC s backBuf pst
599599 gobuf !_ s backBuf fp@(Tuple' end contents) !cur !pst = do
600− x <- liftIO $ peekWith contents cur
600+ x <- liftIO $ peekByteIndex contents cur
601601 pRes <- pstep pst x
602602 let next = INDEX_NEXT(cur,a)
603603 case pRes of
@@ -669,7 +669,7 @@ parseBreakK (PRD.Parser pstep initial extract) stream = do
669669 -- Use strictness on "cur" to keep it unboxed
670670 goArray !pst backBuf st (Array _ cur end) | cur == end = go pst st backBuf
671671 goArray !pst backBuf st (Array contents cur end) = do
672− x <- liftIO $ peekWith contents cur
672+ x <- liftIO $ peekByteIndex cur contents
673673 pRes <- pstep pst x
674674 let next = INDEX_NEXT(cur,a)
675675 case pRes of
@@ -714,7 +714,7 @@ parseBreakK (PRD.Parser pstep initial extract) stream = do
714714 goExtract !pst backBuf (Array _ cur end)
715715 | cur == end = goStop pst backBuf
716716 goExtract !pst backBuf (Array contents cur end) = do
717− x <- liftIO $ peekWith contents cur
717+ x <- liftIO $ peekByteIndex cur contents
718718 pRes <- pstep pst x
719719 let next = INDEX_NEXT(cur,a)
720720 case pRes of
core/src/Streamly/Internal/Data/Unbox.hs−14
@@ -7,8 +7,6 @@
77
88module Streamly.Internal.Data.Unbox
99 ( Unbox(..)
10− , peekWith
11− , pokeWith
1210 , MutableByteArray(..)
1311 , touch
1412 , getMutableByteArray#
@@ -482,18 +480,6 @@ instance Unbox Bool where
482480 {-# INLINE sizeOf #-}
483481 sizeOf _ = 1
484482
485−--------------------------------------------------------------------------------
486−-- Functions
487−--------------------------------------------------------------------------------
488−
489−{-# INLINE peekWith #-}
490−peekWith :: Unbox a => MutableByteArray -> Int -> IO a
491−peekWith arr i = peekByteIndex i arr
492−
493−{-# INLINE pokeWith #-}
494−pokeWith :: Unbox a => MutableByteArray -> Int -> a -> IO ()
495−pokeWith arr i = pokeByteIndex i arr
496−
497483--------------------------------------------------------------------------------
498484-- Generic deriving
499485--------------------------------------------------------------------------------
core/src/Streamly/Internal/Unicode/Stream.hs+3−3
@@ -108,7 +108,7 @@ import Streamly.Internal.Data.Stream (Stream)
108108import Streamly.Internal.Data.Stream (Step (..))
109109import Streamly.Internal.Data.SVar.Type (adaptState)
110110import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
111−import Streamly.Internal.Data.Unbox (peekWith)
111+import Streamly.Internal.Data.Unbox (Unbox(peekByteIndex))
112112import Streamly.Internal.Data.Unfold.Type (Unfold(..))
113113import Streamly.Internal.System.IO (unsafeInlineIO)
114114
@@ -745,7 +745,7 @@ decodeUtf8ArraysWithD cfm (D.Stream step state) =
745745 | p == end = do
746746 return $ Skip $ OuterLoop st Nothing
747747 step' _ _ (InnerLoopDecodeInit st contents p end) = do
748− x <- liftIO $ peekWith contents p
748+ x <- liftIO $ peekByteIndex p contents
749749 -- Note: It is important to use a ">" instead of a "<=" test here for
750750 -- GHC to generate code layout for default branch prediction for the
751751 -- common case. This is fragile and might change with the compiler
@@ -779,7 +779,7 @@ decodeUtf8ArraysWithD cfm (D.Stream step state) =
779779 step' _ _ (InnerLoopDecoding st _ p end sv cp)
780780 | p == end = return $ Skip $ OuterLoop st (Just (sv, cp))
781781 step' table _ (InnerLoopDecoding st contents p end statePtr codepointPtr) = do
782− x <- liftIO $ peekWith contents p
782+ x <- liftIO $ peekByteIndex p contents
783783 let (Tuple' sv cp) = decode1 table statePtr codepointPtr x
784784 return $
785785 case sv of