on master help sign in
Rename peekByteIndex/pokeByteIndex to peekAt/pokeAt
1efeed4Harendra Kumar
benchmark/Streamly/Benchmark/Data/Serialize.hs+2−2
@@ -44,8 +44,8 @@ import Streamly.Benchmark.Data.Serialize.RecNonCompatible
44#ifdef USE_UNBOX
44#ifdef USE_UNBOX
45#define SERIALIZE_CLASS Unbox
45#define SERIALIZE_CLASS Unbox
46#define DERIVE_CLASS(typ) $(deriveUnbox [d|instance Unbox typ|])
46#define DERIVE_CLASS(typ) $(deriveUnbox [d|instance Unbox typ|])
47−#define SERIALIZE_OP pokeByteIndex
47+#define SERIALIZE_OP pokeAt
48−#define DESERIALIZE_OP peekByteIndex
48+#define DESERIALIZE_OP peekAt
49#else
49#else
50#define SERIALIZE_CLASS Serialize
50#define SERIALIZE_CLASS Serialize
51#define DERIVE_CLASS(typ) $(deriveSerialize [d|instance Serialize typ|])
51#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
220 --
220 --
221 -- This should be safe as the array contents are guaranteed to be
221 -- This should be safe as the array contents are guaranteed to be
222 -- evaluated/written to before we peek at them.
222 -- evaluated/written to before we peek at them.
223− let !x = unsafeInlineIO $ peekByteIndex p contents
223+ let !x = unsafeInlineIO $ peekAt p contents
224 let !p1 = INDEX_NEXT(p,a)
224 let !p1 = INDEX_NEXT(p,a)
225 return $ D.Yield x (ArrayUnsafe contents end p1)
225 return $ D.Yield x (ArrayUnsafe contents end p1)
226
226
@@ -243,7 +243,7 @@ getIndexRev i arr =
243 $ do
243 $ do
244 let elemPtr = RINDEX_OF(arrEnd arr, i, a)
244 let elemPtr = RINDEX_OF(arrEnd arr, i, a)
245 if i >= 0 && elemPtr >= arrStart arr
245 if i >= 0 && elemPtr >= arrStart arr
246− then Just <$> peekByteIndex elemPtr (arrContents arr)
246+ then Just <$> peekAt elemPtr (arrContents arr)
247 else return Nothing
247 else return Nothing
248
248
249-- |
249-- |
@@ -404,7 +404,7 @@ getIndex i arr =
404 $ do
404 $ do
405 let elemPtr = INDEX_OF(arrStart arr, i, a)
405 let elemPtr = INDEX_OF(arrStart arr, i, a)
406 if i >= 0 && INDEX_VALID(elemPtr, arrEnd arr, a)
406 if i >= 0 && INDEX_VALID(elemPtr, arrEnd arr, a)
407− then Just <$> peekByteIndex elemPtr (arrContents arr)
407+ then Just <$> peekAt elemPtr (arrContents arr)
408 else return Nothing
408 else return Nothing
409
409
410-- | Given a stream of array indices, read the elements on those indices from
410-- | 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
501 -- accumulating the list and fusing better with the pure consumers.
501 -- accumulating the list and fusing better with the pure consumers.
502 --
502 --
503 -- This should be safe as the array contents are guaranteed to be
503 -- This should be safe as the array contents are guaranteed to be
504− -- evaluated/written to before we peekByteIndex at them.
504+ -- evaluated/written to before we peekAt at them.
505− let !x = unsafeInlineIO $ peekByteIndex p arrContents
505+ let !x = unsafeInlineIO $ peekAt p arrContents
506 in c x (go (INDEX_NEXT(p,a)))
506 in c x (go (INDEX_NEXT(p,a)))
507
507
508-- | Convert an 'Array' into a list.
508-- | Convert an 'Array' into a list.
@@ -703,7 +703,7 @@ _toStreamD_ size Array{..} = D.Stream step arrStart
703 {-# INLINE_LATE step #-}
703 {-# INLINE_LATE step #-}
704 step _ p | p == arrEnd = return D.Stop
704 step _ p | p == arrEnd = return D.Stop
705 step _ p = liftIO $ do
705 step _ p = liftIO $ do
706− x <- peekByteIndex p arrContents
706+ x <- peekAt p arrContents
707 return $ D.Yield x (p + size)
707 return $ D.Yield x (p + size)
708
708
709{-
709{-
core/src/Streamly/Internal/Data/Fold/Chunked.hs+2−2
@@ -124,7 +124,7 @@ fromFold (Fold.Fold fstep finitial _ ffinal) =
124 assert (cur == end) (return ())
124 assert (cur == end) (return ())
125 return $ Partial 0 fs
125 return $ Partial 0 fs
126 goArray !_ !cur !fs = do
126 goArray !_ !cur !fs = do
127− x <- liftIO $ peekByteIndex cur contents
127+ x <- liftIO $ peekAt cur contents
128 res <- fstep fs x
128 res <- fstep fs x
129 let elemSize = SIZE_OF(a)
129 let elemSize = SIZE_OF(a)
130 next = INDEX_NEXT(cur,a)
130 next = INDEX_NEXT(cur,a)
@@ -163,7 +163,7 @@ fromParserD (ParserD.Parser step1 initial1 extract1) =
163 else return $ st (arrRem + n) fs1
163 else return $ st (arrRem + n) fs1
164
164
165 goArray !_ !cur !fs = do
165 goArray !_ !cur !fs = do
166− x <- liftIO $ peekByteIndex cur contents
166+ x <- liftIO $ peekAt cur contents
167 res <- step1 fs x
167 res <- step1 fs x
168 let elemSize = SIZE_OF(a)
168 let elemSize = SIZE_OF(a)
169 next = INDEX_NEXT(cur,a)
169 next = INDEX_NEXT(cur,a)
core/src/Streamly/Internal/Data/IORef/Unboxed.hs+3−3
@@ -56,7 +56,7 @@ newtype IORef a = IORef MutByteArray
56newIORef :: forall a. Unbox a => a -> IO (IORef a)
56newIORef :: forall a. Unbox a => a -> IO (IORef a)
57newIORef x = do
57newIORef x = do
58 var <- MBA.new (sizeOf (Proxy :: Proxy a))
58 var <- MBA.new (sizeOf (Proxy :: Proxy a))
59− pokeByteIndex 0 var x
59+ pokeAt 0 var x
60 return $ IORef var
60 return $ IORef var
61
61
62-- | Write a value to an 'IORef'.
62-- | Write a value to an 'IORef'.
@@ -64,14 +64,14 @@ newIORef x = do
64-- /Pre-release/
64-- /Pre-release/
65{-# INLINE writeIORef #-}
65{-# INLINE writeIORef #-}
66writeIORef :: Unbox a => IORef a -> a -> IO ()
66writeIORef :: Unbox a => IORef a -> a -> IO ()
67−writeIORef (IORef var) = pokeByteIndex 0 var
67+writeIORef (IORef var) = pokeAt 0 var
68
68
69-- | Read a value from an 'IORef'.
69-- | Read a value from an 'IORef'.
70--
70--
71-- /Pre-release/
71-- /Pre-release/
72{-# INLINE readIORef #-}
72{-# INLINE readIORef #-}
73readIORef :: Unbox a => IORef a -> IO a
73readIORef :: Unbox a => IORef a -> IO a
74−readIORef (IORef var) = peekByteIndex 0 var
74+readIORef (IORef var) = peekAt 0 var
75
75
76-- | Modify the value of an 'IORef' using a function with strict application.
76-- | Modify the value of an 'IORef' using a function with strict application.
77--
77--
core/src/Streamly/Internal/Data/MutArray/Type.hs+37−37
@@ -500,7 +500,7 @@ putIndexUnsafe :: forall m a. (MonadIO m, Unbox a)
500putIndexUnsafe i MutArray{..} x = do
500putIndexUnsafe i MutArray{..} x = do
501 let index = INDEX_OF(arrStart, i, a)
501 let index = INDEX_OF(arrStart, i, a)
502 assert (i >= 0 && INDEX_VALID(index, arrEnd, a)) (return ())
502 assert (i >= 0 && INDEX_VALID(index, arrEnd, a)) (return ())
503− liftIO $ pokeByteIndex index arrContents x
503+ liftIO $ pokeAt index arrContents x
504
504
505invalidIndex :: String -> Int -> a
505invalidIndex :: String -> Int -> a
506invalidIndex label i =
506invalidIndex label i =
@@ -518,7 +518,7 @@ putIndex :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> a -> m ()
518putIndex i MutArray{..} x = do
518putIndex i MutArray{..} x = do
519 let index = INDEX_OF(arrStart,i,a)
519 let index = INDEX_OF(arrStart,i,a)
520 if i >= 0 && INDEX_VALID(index,arrEnd,a)
520 if i >= 0 && INDEX_VALID(index,arrEnd,a)
521− then liftIO $ pokeByteIndex index arrContents x
521+ then liftIO $ pokeAt index arrContents x
522 else invalidIndex "putIndex" i
522 else invalidIndex "putIndex" i
523
523
524-- | Write an input stream of (index, value) pairs to an array. Throws an
524-- | 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) =>
544modifyIndexUnsafe i MutArray{..} f = liftIO $ do
544modifyIndexUnsafe i MutArray{..} f = liftIO $ do
545 let index = INDEX_OF(arrStart,i,a)
545 let index = INDEX_OF(arrStart,i,a)
546 assert (i >= 0 && INDEX_NEXT(index,a) <= arrEnd) (return ())
546 assert (i >= 0 && INDEX_NEXT(index,a) <= arrEnd) (return ())
547− r <- peekByteIndex index arrContents
547+ r <- peekAt index arrContents
548 let (x, res) = f r
548 let (x, res) = f r
549− pokeByteIndex index arrContents x
549+ pokeAt index arrContents x
550 return res
550 return res
551
551
552-- | Modify a given index of an array using a modifier function.
552-- | Modify a given index of an array using a modifier function.
@@ -558,9 +558,9 @@ modifyIndex i MutArray{..} f = do
558 let index = INDEX_OF(arrStart,i,a)
558 let index = INDEX_OF(arrStart,i,a)
559 if i >= 0 && INDEX_VALID(index,arrEnd,a)
559 if i >= 0 && INDEX_VALID(index,arrEnd,a)
560 then liftIO $ do
560 then liftIO $ do
561− r <- peekByteIndex index arrContents
561+ r <- peekAt index arrContents
562 let (x, res) = f r
562 let (x, res) = f r
563− pokeByteIndex index arrContents x
563+ pokeAt index arrContents x
564 return res
564 return res
565 else invalidIndex "modifyIndex" i
565 else invalidIndex "modifyIndex" i
566
566
@@ -594,8 +594,8 @@ modify MutArray{..} f = liftIO $
594
594
595 go i =
595 go i =
596 when (INDEX_VALID(i,arrEnd,a)) $ do
596 when (INDEX_VALID(i,arrEnd,a)) $ do
597− r <- peekByteIndex i arrContents
597+ r <- peekAt i arrContents
598− pokeByteIndex i arrContents (f r)
598+ pokeAt i arrContents (f r)
599 go (INDEX_NEXT(i,a))
599 go (INDEX_NEXT(i,a))
600
600
601-- XXX We could specify the number of bytes to swap instead of Proxy. Need
601-- XXX We could specify the number of bytes to swap instead of Proxy. Need
@@ -609,10 +609,10 @@ swapArrayByteIndices ::
609 -> Int
609 -> Int
610 -> IO ()
610 -> IO ()
611swapArrayByteIndices _ arrContents i1 i2 = do
611swapArrayByteIndices _ arrContents i1 i2 = do
612− r1 <- peekByteIndex i1 arrContents
612+ r1 <- peekAt i1 arrContents
613− r2 <- peekByteIndex i2 arrContents
613+ r2 <- peekAt i2 arrContents
614− pokeByteIndex i1 arrContents (r2 :: a)
614+ pokeAt i1 arrContents (r2 :: a)
615− pokeByteIndex i2 arrContents (r1 :: a)
615+ pokeAt i2 arrContents (r1 :: a)
616
616
617-- | Swap the elements at two indices without validating the indices.
617-- | Swap the elements at two indices without validating the indices.
618--
618--
@@ -889,7 +889,7 @@ rightSize arr@MutArray{..} = do
889snocNewEnd :: (MonadIO m, Unbox a) => Int -> MutArray a -> a -> m (MutArray a)
889snocNewEnd :: (MonadIO m, Unbox a) => Int -> MutArray a -> a -> m (MutArray a)
890snocNewEnd newEnd arr@MutArray{..} x = liftIO $ do
890snocNewEnd newEnd arr@MutArray{..} x = liftIO $ do
891 assert (newEnd <= arrBound) (return ())
891 assert (newEnd <= arrBound) (return ())
892− pokeByteIndex arrEnd arrContents x
892+ pokeAt arrEnd arrContents x
893 return $ arr {arrEnd = newEnd}
893 return $ arr {arrEnd = newEnd}
894
894
895-- | Really really unsafe, appends the element into the first array, may
895-- | 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
1003getIndexUnsafe i MutArray{..} = do
1003getIndexUnsafe i MutArray{..} = do
1004 let index = INDEX_OF(arrStart,i,a)
1004 let index = INDEX_OF(arrStart,i,a)
1005 assert (i >= 0 && INDEX_VALID(index,arrEnd,a)) (return ())
1005 assert (i >= 0 && INDEX_VALID(index,arrEnd,a)) (return ())
1006− liftIO $ peekByteIndex index arrContents
1006+ liftIO $ peekAt index arrContents
1007
1007
1008-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
1008-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
1009--
1009--
@@ -1012,7 +1012,7 @@ getIndex :: forall m a. (MonadIO m, Unbox a) => Int -> MutArray a -> m (Maybe a)
1012getIndex i MutArray{..} = do
1012getIndex i MutArray{..} = do
1013 let index = INDEX_OF(arrStart,i,a)
1013 let index = INDEX_OF(arrStart,i,a)
1014 if i >= 0 && INDEX_VALID(index,arrEnd,a)
1014 if i >= 0 && INDEX_VALID(index,arrEnd,a)
1015− then liftIO $ Just <$> peekByteIndex index arrContents
1015+ then liftIO $ Just <$> peekAt index arrContents
1016 else return Nothing
1016 else return Nothing
1017
1017
1018-- | /O(1)/ Lookup the element at the given index from the end of the array.
1018-- | /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
1025getIndexRev i MutArray{..} = do
1025getIndexRev i MutArray{..} = do
1026 let index = RINDEX_OF(arrEnd,i,a)
1026 let index = RINDEX_OF(arrEnd,i,a)
1027 if i >= 0 && index >= arrStart
1027 if i >= 0 && index >= arrStart
1028− then liftIO $ peekByteIndex index arrContents
1028+ then liftIO $ peekAt index arrContents
1029 else invalidIndex "getIndexRev" i
1029 else invalidIndex "getIndexRev" i
1030
1030
1031data GetIndicesState contents start end st =
1031data GetIndicesState contents start end st =
@@ -1165,7 +1165,7 @@ partitionBy f arr@MutArray{..} = liftIO $ do
1165
1165
1166 -- Invariant low < high on entry, and on return as well
1166 -- Invariant low < high on entry, and on return as well
1167 moveHigh low high = do
1167 moveHigh low high = do
1168− h <- peekByteIndex high arrContents
1168+ h <- peekAt high arrContents
1169 if f h
1169 if f h
1170 then
1170 then
1171 -- Correctly classified, continue the loop
1171 -- Correctly classified, continue the loop
@@ -1185,7 +1185,7 @@ partitionBy f arr@MutArray{..} = liftIO $ do
1185 -- low <= high
1185 -- low <= high
1186 -- Both low and high are valid locations within the array
1186 -- Both low and high are valid locations within the array
1187 go low high = do
1187 go low high = do
1188− l <- peekByteIndex low arrContents
1188+ l <- peekAt low arrContents
1189 if f l
1189 if f l
1190 then
1190 then
1191 -- low is wrongly classified
1191 -- low is wrongly classified
@@ -1196,8 +1196,8 @@ partitionBy f arr@MutArray{..} = liftIO $ do
1196 case r of
1196 case r of
1197 Nothing -> return low
1197 Nothing -> return low
1198 Just (high1, h) -> do -- low < high1
1198 Just (high1, h) -> do -- low < high1
1199− pokeByteIndex low arrContents h
1199+ pokeAt low arrContents h
1200− pokeByteIndex high1 arrContents l
1200+ pokeAt high1 arrContents l
1201 let low1 = INDEX_NEXT(low,a)
1201 let low1 = INDEX_NEXT(low,a)
1202 high2 = INDEX_PREV(high1,a)
1202 high2 = INDEX_PREV(high1,a)
1203 if low1 <= high2
1203 if low1 <= high2
@@ -1331,7 +1331,7 @@ chunksOfAs ps n (D.Stream step state) =
1331 r <- step (adaptState gst) st
1331 r <- step (adaptState gst) st
1332 case r of
1332 case r of
1333 D.Yield x s -> do
1333 D.Yield x s -> do
1334− liftIO $ pokeByteIndex end contents x
1334+ liftIO $ pokeAt end contents x
1335 let end1 = INDEX_NEXT(end,a)
1335 let end1 = INDEX_NEXT(end,a)
1336 return $
1336 return $
1337 if end1 >= bound
1337 if end1 >= bound
@@ -1418,7 +1418,7 @@ flattenArrays (D.Stream step state) = D.Stream step' (OuterLoop state)
1418 return $ D.Skip $ OuterLoop st
1418 return $ D.Skip $ OuterLoop st
1419
1419
1420 step' _ (InnerLoop st contents p end) = do
1420 step' _ (InnerLoop st contents p end) = do
1421− x <- liftIO $ peekByteIndex p contents
1421+ x <- liftIO $ peekAt p contents
1422 return $ D.Yield x (InnerLoop st contents (INDEX_NEXT(p,a)) end)
1422 return $ D.Yield x (InnerLoop st contents (INDEX_NEXT(p,a)) end)
1423
1423
1424-- | Use the "readerRev" unfold instead.
1424-- | Use the "readerRev" unfold instead.
@@ -1448,7 +1448,7 @@ flattenArraysRev (D.Stream step state) = D.Stream step' (OuterLoop state)
1448 return $ D.Skip $ OuterLoop st
1448 return $ D.Skip $ OuterLoop st
1449
1449
1450 step' _ (InnerLoop st contents p start) = do
1450 step' _ (InnerLoop st contents p start) = do
1451− x <- liftIO $ peekByteIndex p contents
1451+ x <- liftIO $ peekAt p contents
1452 let cur = INDEX_PREV(p,a)
1452 let cur = INDEX_PREV(p,a)
1453 return $ D.Yield x (InnerLoop st contents cur start)
1453 return $ D.Yield x (InnerLoop st contents cur start)
1454
1454
@@ -1487,7 +1487,7 @@ producerWith liftio = Producer step (return . toArrayUnsafe) extract
1487 -- few actions for correctness and execution order sanity. We want
1487 -- few actions for correctness and execution order sanity. We want
1488 -- the peek to occur right here and not lazily at some later point
1488 -- the peek to occur right here and not lazily at some later point
1489 -- because we want the peek to be ordered with respect to the touch.
1489 -- 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
1491 return $ D.Yield x (ArrayUnsafe contents (INDEX_NEXT(cur,a)) end)
1491 return $ D.Yield x (ArrayUnsafe contents (INDEX_NEXT(cur,a)) end)
1492
1492
1493 extract = return . fromArrayUnsafe
1493 extract = return . fromArrayUnsafe
@@ -1518,7 +1518,7 @@ readerRevWith liftio = Unfold step inject
1518 {-# INLINE_LATE step #-}
1518 {-# INLINE_LATE step #-}
1519 step (ArrayUnsafe _ start p) | p < start = return D.Stop
1519 step (ArrayUnsafe _ start p) | p < start = return D.Stop
1520 step (ArrayUnsafe contents start p) = do
1520 step (ArrayUnsafe contents start p) = do
1521− !x <- liftio $ peekByteIndex p contents
1521+ !x <- liftio $ peekAt p contents
1522 return $ D.Yield x (ArrayUnsafe contents start (INDEX_PREV(p,a)))
1522 return $ D.Yield x (ArrayUnsafe contents start (INDEX_PREV(p,a)))
1523
1523
1524-- | Unfold an array into a stream in reverse order.
1524-- | Unfold an array into a stream in reverse order.
@@ -1549,7 +1549,7 @@ toListFB c n MutArray{..} = go arrStart
1549 -- evaluated/written to before we peek at them.
1549 -- evaluated/written to before we peek at them.
1550 -- XXX
1550 -- XXX
1551 let !x = unsafeInlineIO $ do
1551 let !x = unsafeInlineIO $ do
1552− r <- peekByteIndex arrContents p
1552+ r <- peekAt arrContents p
1553 return r
1553 return r
1554 in c x (go (PTR_NEXT(p,a)))
1554 in c x (go (PTR_NEXT(p,a)))
1555-}
1555-}
@@ -1566,7 +1566,7 @@ toList MutArray{..} = liftIO $ go arrStart
1566
1566
1567 go p | assert (p <= arrEnd) (p == arrEnd) = return []
1567 go p | assert (p <= arrEnd) (p == arrEnd) = return []
1568 go p = do
1568 go p = do
1569− x <- peekByteIndex p arrContents
1569+ x <- peekAt p arrContents
1570 (:) x <$> go (INDEX_NEXT(p,a))
1570 (:) x <$> go (INDEX_NEXT(p,a))
1571
1571
1572{-# INLINE_NORMAL toStreamDWith #-}
1572{-# INLINE_NORMAL toStreamDWith #-}
@@ -1580,7 +1580,7 @@ toStreamDWith liftio MutArray{..} = D.Stream step arrStart
1580 {-# INLINE_LATE step #-}
1580 {-# INLINE_LATE step #-}
1581 step _ p | assert (p <= arrEnd) (p == arrEnd) = return D.Stop
1581 step _ p | assert (p <= arrEnd) (p == arrEnd) = return D.Stop
1582 step _ p = liftio $ do
1582 step _ p = liftio $ do
1583− r <- peekByteIndex p arrContents
1583+ r <- peekAt p arrContents
1584 return $ D.Yield r (INDEX_NEXT(p,a))
1584 return $ D.Yield r (INDEX_NEXT(p,a))
1585
1585
1586-- | Convert a 'MutArray' into a stream.
1586-- | Convert a 'MutArray' into a stream.
@@ -1601,7 +1601,7 @@ toStreamKWith liftio MutArray{..} = go arrStart
1601
1601
1602 go p | assert (p <= arrEnd) (p == arrEnd) = K.nil
1602 go p | assert (p <= arrEnd) (p == arrEnd) = K.nil
1603 | otherwise =
1603 | otherwise =
1604− let elemM = peekByteIndex p arrContents
1604+ let elemM = peekAt p arrContents
1605 in liftio elemM `K.consM` go (INDEX_NEXT(p,a))
1605 in liftio elemM `K.consM` go (INDEX_NEXT(p,a))
1606
1606
1607{-# INLINE toStreamK #-}
1607{-# INLINE toStreamK #-}
@@ -1621,7 +1621,7 @@ toStreamDRevWith liftio MutArray{..} =
1621 {-# INLINE_LATE step #-}
1621 {-# INLINE_LATE step #-}
1622 step _ p | p < arrStart = return D.Stop
1622 step _ p | p < arrStart = return D.Stop
1623 step _ p = liftio $ do
1623 step _ p = liftio $ do
1624− r <- peekByteIndex p arrContents
1624+ r <- peekAt p arrContents
1625 return $ D.Yield r (INDEX_PREV(p,a))
1625 return $ D.Yield r (INDEX_PREV(p,a))
1626
1626
1627-- | Convert a 'MutArray' into a stream in reverse order.
1627-- | Convert a 'MutArray' into a stream in reverse order.
@@ -1644,7 +1644,7 @@ toStreamKRevWith liftio MutArray {..} =
1644
1644
1645 go p | p < arrStart = K.nil
1645 go p | p < arrStart = K.nil
1646 | otherwise =
1646 | otherwise =
1647− let elemM = peekByteIndex p arrContents
1647+ let elemM = peekAt p arrContents
1648 in liftio elemM `K.consM` go (INDEX_PREV(p,a))
1648 in liftio elemM `K.consM` go (INDEX_PREV(p,a))
1649
1649
1650{-# INLINE toStreamKRev #-}
1650{-# INLINE toStreamKRev #-}
@@ -1712,7 +1712,7 @@ writeAppendNUnsafe n action =
1712 return $ toArrayUnsafe arr1
1712 return $ toArrayUnsafe arr1
1713
1713
1714 step (ArrayUnsafe contents start end) x = do
1714 step (ArrayUnsafe contents start end) x = do
1715− liftIO $ pokeByteIndex end contents x
1715+ liftIO $ pokeAt end contents x
1716 return $ ArrayUnsafe contents start (INDEX_NEXT(end,a))
1716 return $ ArrayUnsafe contents start (INDEX_NEXT(end,a))
1717
1717
1718-- | Append @n@ elements to an existing array. Any free space left in the array
1718-- | 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
1772 initial = toArrayUnsafe <$> alloc (max n 0)
1772 initial = toArrayUnsafe <$> alloc (max n 0)
1773
1773
1774 step (ArrayUnsafe contents start end) x = do
1774 step (ArrayUnsafe contents start end) x = do
1775− liftIO $ pokeByteIndex end contents x
1775+ liftIO $ pokeAt end contents x
1776 return
1776 return
1777 $ ArrayUnsafe contents start (INDEX_NEXT(end,a))
1777 $ ArrayUnsafe contents start (INDEX_NEXT(end,a))
1778
1778
@@ -1855,7 +1855,7 @@ writeRevNWithUnsafe alloc n = fromArrayUnsafe <$> FL.foldlM' step initial
1855
1855
1856 step (ArrayUnsafe contents start end) x = do
1856 step (ArrayUnsafe contents start end) x = do
1857 let ptr = INDEX_PREV(start,a)
1857 let ptr = INDEX_PREV(start,a)
1858− liftIO $ pokeByteIndex ptr contents x
1858+ liftIO $ pokeAt ptr contents x
1859 return
1859 return
1860 $ ArrayUnsafe contents ptr end
1860 $ ArrayUnsafe contents ptr end
1861
1861
@@ -1994,7 +1994,7 @@ fromStreamDNAs ps limit str = do
1994 where
1994 where
1995
1995
1996 fwrite arrContents ptr x = do
1996 fwrite arrContents ptr x = do
1997− liftIO $ pokeByteIndex ptr arrContents x
1997+ liftIO $ pokeAt ptr arrContents x
1998 return $ INDEX_NEXT(ptr,a)
1998 return $ INDEX_NEXT(ptr,a)
1999
1999
2000-- | Use the 'writeN' fold instead.
2000-- | Use the 'writeN' fold instead.
@@ -2416,7 +2416,7 @@ strip eq arr@MutArray{..} = liftIO $ do
2416 getStart cur = do
2416 getStart cur = do
2417 if cur < arrEnd
2417 if cur < arrEnd
2418 then do
2418 then do
2419− r <- peekByteIndex cur arrContents
2419+ r <- peekAt cur arrContents
2420 if eq r
2420 if eq r
2421 then getStart (INDEX_NEXT(cur,a))
2421 then getStart (INDEX_NEXT(cur,a))
2422 else return cur
2422 else return cur
@@ -2426,7 +2426,7 @@ strip eq arr@MutArray{..} = liftIO $ do
2426 if cur > low
2426 if cur > low
2427 then do
2427 then do
2428 let prev = INDEX_PREV(cur,a)
2428 let prev = INDEX_PREV(cur,a)
2429− r <- peekByteIndex prev arrContents
2429+ r <- peekAt prev arrContents
2430 if eq r
2430 if eq r
2431 then getLast prev low
2431 then getLast prev low
2432 else return cur
2432 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
404 go !_ !cur !pst | cur >= end =
404 go !_ !cur !pst | cur >= end =
405 onContinue ((end - start) `div` SIZE_OF(a)) pst
405 onContinue ((end - start) `div` SIZE_OF(a)) pst
406 go !_ !cur !pst = do
406 go !_ !cur !pst = do
407− let !x = unsafeInlineIO $ peekByteIndex cur contents
407+ let !x = unsafeInlineIO $ peekAt cur contents
408 pRes <- pstep pst x
408 pRes <- pstep pst x
409 let elemSize = SIZE_OF(a)
409 let elemSize = SIZE_OF(a)
410 next = INDEX_NEXT(cur,a)
410 next = INDEX_NEXT(cur,a)
core/src/Streamly/Internal/Data/Ring.hs+3−3
@@ -79,7 +79,7 @@ import Foreign.Storable
79import Foreign.ForeignPtr (ForeignPtr, withForeignPtr, touchForeignPtr)
79import Foreign.ForeignPtr (ForeignPtr, withForeignPtr, touchForeignPtr)
80import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
80import Foreign.ForeignPtr.Unsafe (unsafeForeignPtrToPtr)
81import Foreign.Ptr (plusPtr, minusPtr, castPtr)
81import 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))
83import GHC.ForeignPtr (mallocPlainForeignPtrAlignedBytes)
83import GHC.ForeignPtr (mallocPlainForeignPtrAlignedBytes)
84import GHC.Ptr (Ptr(..))
84import GHC.Ptr (Ptr(..))
85import Streamly.Internal.Data.MutArray.Type (MutArray)
85import Streamly.Internal.Data.MutArray.Type (MutArray)
@@ -411,7 +411,7 @@ unsafeEqArrayN Ring{..} rh A.Array{..} nBytes
411
411
412 check p i = do
412 check p i = do
413 (relem :: Word8) <- peek p
413 (relem :: Word8) <- peek p
414− aelem <- peekByteIndex i w8Contents
414+ aelem <- peekAt i w8Contents
415 if relem == aelem
415 if relem == aelem
416 then go (p `plusPtr` 1) (i + 1)
416 then go (p `plusPtr` 1) (i + 1)
417 else return False
417 else return False
@@ -445,7 +445,7 @@ unsafeEqArray Ring{..} rh A.Array{..} =
445
445
446 check p i = do
446 check p i = do
447 (relem :: Word8) <- peek p
447 (relem :: Word8) <- peek p
448− aelem <- peekByteIndex i w8Contents
448+ aelem <- peekAt i w8Contents
449 if relem == aelem
449 if relem == aelem
450 then go (p `plusPtr` 1) (i + 1)
450 then go (p `plusPtr` 1) (i + 1)
451 else return False
451 else return False
core/src/Streamly/Internal/Data/Serialize/TH/Bottom.hs+4−4
@@ -341,7 +341,7 @@ xorCmp tag off arr =
341 go8 i = do
341 go8 i = do
342 let wIntegral = litIntegral i
342 let wIntegral = litIntegral i
343 [|xor (unsafeInlineIO
343 [|xor (unsafeInlineIO
344− (Unbox.peekByteIndex
344+ (Unbox.peekAt
345 ($(varE off) + $(litIntegral i))
345 ($(varE off) + $(litIntegral i))
346 $(varE arr)))
346 $(varE arr)))
347 ($(wIntegral) :: Word8) .|.
347 ($(wIntegral) :: Word8) .|.
@@ -355,7 +355,7 @@ xorCmp tag off arr =
355 litIntegral
355 litIntegral
356 (shiftAdd w8_w16 [tag !! i, tag !! (i + 1)] :: Word16)
356 (shiftAdd w8_w16 [tag !! i, tag !! (i + 1)] :: Word16)
357 [|xor (unsafeInlineIO
357 [|xor (unsafeInlineIO
358− (Unbox.peekByteIndex
358+ (Unbox.peekAt
359 ($(varE off) + $(litIntegral i))
359 ($(varE off) + $(litIntegral i))
360 $(varE arr)))
360 $(varE arr)))
361 ($(wIntegral) :: Word16) .|.
361 ($(wIntegral) :: Word16) .|.
@@ -375,7 +375,7 @@ xorCmp tag off arr =
375 , tag !! (i + 3)
375 , tag !! (i + 3)
376 ] :: Word32)
376 ] :: Word32)
377 [|xor (unsafeInlineIO
377 [|xor (unsafeInlineIO
378− (Unbox.peekByteIndex
378+ (Unbox.peekAt
379 ($(varE off) + $(litIntegral i))
379 ($(varE off) + $(litIntegral i))
380 $(varE arr)))
380 $(varE arr)))
381 ($(wIntegral) :: Word32) .|.
381 ($(wIntegral) :: Word32) .|.
@@ -399,7 +399,7 @@ xorCmp tag off arr =
399 , tag !! (i + 7)
399 , tag !! (i + 7)
400 ])
400 ])
401 [|xor (unsafeInlineIO
401 [|xor (unsafeInlineIO
402− (Unbox.peekByteIndex
402+ (Unbox.peekAt
403 ($(varE off) + $(litIntegral i))
403 ($(varE off) + $(litIntegral i))
404 $(varE arr)))
404 $(varE arr)))
405 ($(wIntegral) :: Word64) .|.
405 ($(wIntegral) :: Word64) .|.
core/src/Streamly/Internal/Data/Serialize/TH/RecHeader.hs+2−2
@@ -228,7 +228,7 @@ headerValue (SimpleDataCon _ fields) =
228serializeWithSize :: Serialize a => Int -> MutByteArray -> a -> IO Int
228serializeWithSize :: Serialize a => Int -> MutByteArray -> a -> IO Int
229serializeWithSize off arr val = do
229serializeWithSize off arr val = do
230 off1 <- serialize (off + 4) arr val
230 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)
232 pure off1
232 pure off1
233
233
234mkRecSerializeExpr :: Name -> SimpleDataCon -> Q Exp
234mkRecSerializeExpr :: Name -> SimpleDataCon -> Q Exp
@@ -245,7 +245,7 @@ mkRecSerializeExpr initialOffset (con@(SimpleDataCon cname fields)) = do
245 $(varP (makeI 0)) <- $(serializeW8List afterHLen _arr hval)
245 $(varP (makeI 0)) <- $(serializeW8List afterHLen _arr hval)
246 let $(openConstructor cname (length fields)) = $(varE _val)
246 let $(openConstructor cname (length fields)) = $(varE _val)
247 finalOff <- $(mkSerializeExprFields 'serializeWithSize fields)
247 finalOff <- $(mkSerializeExprFields 'serializeWithSize fields)
248− Unbox.pokeByteIndex
248+ Unbox.pokeAt
249 $(varE initialOffset)
249 $(varE initialOffset)
250 $(varE _arr)
250 $(varE _arr)
251 ((fromIntegral :: Int -> Word32)
251 ((fromIntegral :: Int -> Word32)
core/src/Streamly/Internal/Data/Serialize/Type.hs+3−3
@@ -189,7 +189,7 @@ deserializeUnsafe off arr sz =
189 in do
189 in do
190 -- Keep likely path in the straight branch.
190 -- Keep likely path in the straight branch.
191 if (next <= sz)
191 if (next <= sz)
192− then Unbox.peekByteIndex off arr >>= \val -> pure (next, val)
192+ then Unbox.peekAt off arr >>= \val -> pure (next, val)
193 else error
193 else error
194 $ "deserialize: accessing array at offset = "
194 $ "deserialize: accessing array at offset = "
195 ++ show (next - 1)
195 ++ show (next - 1)
@@ -203,7 +203,7 @@ serializeUnsafe off arr val =
203#ifdef DEBUG
203#ifdef DEBUG
204 checkBounds "serialize" next arr
204 checkBounds "serialize" next arr
205#endif
205#endif
206− Unbox.pokeByteIndex off arr val
206+ Unbox.pokeAt off arr val
207 pure next
207 pure next
208
208
209#define DERIVE_SERIALIZE_FROM_UNBOX(_type) \
209#define DERIVE_SERIALIZE_FROM_UNBOX(_type) \
@@ -262,7 +262,7 @@ instance forall a. Serialize a => Serialize [a] where
262 serialize off arr val = do
262 serialize off arr val = do
263 let off1 = off + Unbox.sizeOf (Proxy :: Proxy Int64)
263 let off1 = off + Unbox.sizeOf (Proxy :: Proxy Int64)
264 let pokeList acc o [] =
264 let pokeList acc o [] =
265− Unbox.pokeByteIndex off arr (acc :: Int64) >> pure o
265+ Unbox.pokeAt off arr (acc :: Int64) >> pure o
266 pokeList acc o (x:xs) = do
266 pokeList acc o (x:xs) = do
267 o1 <- serialize o arr x
267 o1 <- serialize o arr x
268 pokeList (acc + 1) o1 xs
268 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(..))
162-- have multiple constructors of different sizes, the size of a sum type is
162-- have multiple constructors of different sizes, the size of a sum type is
163-- computed as the maximum required by any constructor.
163-- computed as the maximum required by any constructor.
164--
164--
165−-- The 'peekByteIndex' operation reads as many bytes from the mutable byte
165+-- The 'peekAt' operation reads as many bytes from the mutable byte
166-- array as the @size@ of the data type and builds a Haskell data type from
166-- 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
168-- binary representation which consists of @size@ bytes and then stores
168-- binary representation which consists of @size@ bytes and then stores
169-- these bytes into the mutable byte array. These operations do not check the
169-- these bytes into the mutable byte array. These operations do not check the
170-- bounds of the array, the user of the type class is expected to check the
170-- 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(..))
214-- >>> :{
214-- >>> :{
215-- instance Unbox Object where
215-- instance Unbox Object where
216-- sizeOf _ = 16
216-- sizeOf _ = 16
217−-- peekByteIndex i arr = do
217+-- peekAt i arr = do
218-- -- Check the array bounds
218-- -- Check the array bounds
219−-- x0 <- peekByteIndex i arr
219+-- x0 <- peekAt i arr
220−-- x1 <- peekByteIndex (i + 8) arr
220+-- x1 <- peekAt (i + 8) arr
221-- return $ Object x0 x1
221-- return $ Object x0 x1
222−-- pokeByteIndex i arr (Object x0 x1) = do
222+-- pokeAt i arr (Object x0 x1) = do
223-- -- Check the array bounds
223-- -- Check the array bounds
224−-- pokeByteIndex i arr x0
224+-- pokeAt i arr x0
225−-- pokeByteIndex (i + 8) arr x1
225+-- pokeAt (i + 8) arr x1
226-- :}
226-- :}
227--
227--
228class Unbox a where
228class Unbox a where
@@ -233,40 +233,49 @@ class Unbox a where
233 default sizeOf :: (SizeOfRep (Rep a)) => Proxy a -> Int
233 default sizeOf :: (SizeOfRep (Rep a)) => Proxy a -> Int
234 sizeOf = genericSizeOf
234 sizeOf = genericSizeOf
235
235
236− -- | @peekByteIndex byte-index array@ reads an element of type @a@ from the
236+ -- | @peekAt byte-offset array@ reads an element of type @a@ from the
237− -- the given the byte index in the array.
237+ -- the given the byte offset in the array.
238 --
238 --
239 -- IMPORTANT: The implementation of this interface may not check the bounds
239 -- IMPORTANT: The implementation of this interface may not check the bounds
240 -- of the array, the caller must not assume that.
240 -- of the array, the caller must not assume that.
241− peekByteIndex :: Int -> MutByteArray -> IO a
241+ peekAt :: Int -> MutByteArray -> IO a
242
242
243− {-# INLINE peekByteIndex #-}
243+ {-# INLINE peekAt #-}
244− default peekByteIndex :: (Generic a, PeekRep (Rep a)) =>
244+ default peekAt :: (Generic a, PeekRep (Rep a)) =>
245 Int -> MutByteArray -> IO a
245 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
247
250
248− -- | @pokeByteIndex byte-index array@ writes an element of type @a@ to the
251+ -- | @pokeAt byte-offset array@ writes an element of type @a@ to the
249− -- the given the byte index in the array.
252+ -- the given the byte offset in the array.
250 --
253 --
251 -- IMPORTANT: The implementation of this interface may not check the bounds
254 -- IMPORTANT: The implementation of this interface may not check the bounds
252 -- of the array, the caller must not assume that.
255 -- of the array, the caller must not assume that.
256+ pokeAt :: Int -> MutByteArray -> a -> IO ()
257+
253 pokeByteIndex :: Int -> MutByteArray -> a -> IO ()
258 pokeByteIndex :: Int -> MutByteArray -> a -> IO ()
259+ pokeByteIndex = pokeAt
254
260
255− {-# INLINE pokeByteIndex #-}
261+ {-# INLINE pokeAt #-}
256− default pokeByteIndex :: (Generic a, PokeRep (Rep a)) =>
262+ default pokeAt :: (Generic a, PokeRep (Rep a)) =>
257 Int -> MutByteArray -> a -> IO ()
263 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." #-}
259
268
260-- XXX Add asserts to check bounds
269-- XXX Add asserts to check bounds
261
270
262#define DERIVE_UNBOXED(_type, _constructor, _readArray, _writeArray, _sizeOf) \
271#define DERIVE_UNBOXED(_type, _constructor, _readArray, _writeArray, _sizeOf) \
263instance Unbox _type where { \
272instance Unbox _type where { \
264−; {-# INLINE peekByteIndex #-} \
273+; {-# INLINE peekAt #-} \
265−; peekByteIndex (I# n) (MutByteArray mbarr) = IO $ \s -> \
274+; peekAt (I# n) (MutByteArray mbarr) = IO $ \s -> \
266 case _readArray mbarr n s of \
275 case _readArray mbarr n s of \
267 { (# s1, i #) -> (# s1, _constructor i #) } \
276 { (# s1, i #) -> (# s1, _constructor i #) } \
268−; {-# INLINE pokeByteIndex #-} \
277+; {-# INLINE pokeAt #-} \
269−; pokeByteIndex (I# n) (MutByteArray mbarr) (_constructor val) = \
278+; pokeAt (I# n) (MutByteArray mbarr) (_constructor val) = \
270 IO $ \s -> (# _writeArray mbarr n val s, () #) \
279 IO $ \s -> (# _writeArray mbarr n val s, () #) \
271; {-# INLINE sizeOf #-} \
280; {-# INLINE sizeOf #-} \
272; sizeOf _ = _sizeOf \
281; sizeOf _ = _sizeOf \
@@ -274,24 +283,24 @@ instance Unbox _type where { \
274
283
275#define DERIVE_WRAPPED_UNBOX(_constraint, _type, _constructor, _innerType) \
284#define DERIVE_WRAPPED_UNBOX(_constraint, _type, _constructor, _innerType) \
276instance _constraint Unbox _type where \
285instance _constraint Unbox _type where \
277−; {-# INLINE peekByteIndex #-} \
286+; {-# INLINE peekAt #-} \
278−; peekByteIndex i arr = _constructor <$> peekByteIndex i arr \
287+; peekAt i arr = _constructor <$> peekAt i arr \
279−; {-# INLINE pokeByteIndex #-} \
288+; {-# INLINE pokeAt #-} \
280−; pokeByteIndex i arr (_constructor a) = pokeByteIndex i arr a \
289+; pokeAt i arr (_constructor a) = pokeAt i arr a \
281; {-# INLINE sizeOf #-} \
290; {-# INLINE sizeOf #-} \
282; sizeOf _ = SIZE_OF(_innerType)
291; sizeOf _ = SIZE_OF(_innerType)
283
292
284#define DERIVE_BINARY_UNBOX(_constraint, _type, _constructor, _innerType) \
293#define DERIVE_BINARY_UNBOX(_constraint, _type, _constructor, _innerType) \
285instance _constraint Unbox _type where { \
294instance _constraint Unbox _type where { \
286−; {-# INLINE peekByteIndex #-} \
295+; {-# INLINE peekAt #-} \
287−; peekByteIndex i arr = \
296+; peekAt i arr = \
288− peekByteIndex i arr >>= \
297+ peekAt i arr >>= \
289− (\p1 -> peekByteIndex (i + SIZE_OF(_innerType)) arr \
298+ (\p1 -> peekAt (i + SIZE_OF(_innerType)) arr \
290 <&> _constructor p1) \
299 <&> _constructor p1) \
291−; {-# INLINE pokeByteIndex #-} \
300+; {-# INLINE pokeAt #-} \
292−; pokeByteIndex i arr (_constructor p1 p2) = \
301+; pokeAt i arr (_constructor p1 p2) = \
293− pokeByteIndex i arr p1 >> \
302+ pokeAt i arr p1 >> \
294− pokeByteIndex (i + SIZE_OF(_innerType)) arr p2 \
303+ pokeAt (i + SIZE_OF(_innerType)) arr p2 \
295; {-# INLINE sizeOf #-} \
304; {-# INLINE sizeOf #-} \
296; sizeOf _ = 2 * SIZE_OF(_innerType) \
305; sizeOf _ = 2 * SIZE_OF(_innerType) \
297}
306}
@@ -413,11 +422,11 @@ DERIVE_BINARY_UNBOX(,Fingerprint,Fingerprint,Word64)
413
422
414instance Unbox () where
423instance Unbox () where
415
424
416− {-# INLINE peekByteIndex #-}
425+ {-# INLINE peekAt #-}
417− peekByteIndex _ _ = return ()
426+ peekAt _ _ = return ()
418
427
419− {-# INLINE pokeByteIndex #-}
428+ {-# INLINE pokeAt #-}
420− pokeByteIndex _ _ _ = return ()
429+ pokeAt _ _ _ = return ()
421
430
422 {-# INLINE sizeOf #-}
431 {-# INLINE sizeOf #-}
423 sizeOf _ = 1
432 sizeOf _ = 1
@@ -425,11 +434,11 @@ instance Unbox () where
425#if MIN_VERSION_base(4,15,0)
434#if MIN_VERSION_base(4,15,0)
426instance Unbox IoSubSystem where
435instance Unbox IoSubSystem where
427
436
428− {-# INLINE peekByteIndex #-}
437+ {-# INLINE peekAt #-}
429− peekByteIndex i arr = toEnum <$> peekByteIndex i arr
438+ peekAt i arr = toEnum <$> peekAt i arr
430
439
431− {-# INLINE pokeByteIndex #-}
440+ {-# INLINE pokeAt #-}
432− pokeByteIndex i arr a = pokeByteIndex i arr (fromEnum a)
441+ pokeAt i arr a = pokeAt i arr (fromEnum a)
433
442
434 {-# INLINE sizeOf #-}
443 {-# INLINE sizeOf #-}
435 sizeOf _ = sizeOf (Proxy :: Proxy Int)
444 sizeOf _ = sizeOf (Proxy :: Proxy Int)
@@ -437,16 +446,16 @@ instance Unbox IoSubSystem where
437
446
438instance Unbox Bool where
447instance Unbox Bool where
439
448
440− {-# INLINE peekByteIndex #-}
449+ {-# INLINE peekAt #-}
441− peekByteIndex i arr = do
450+ peekAt i arr = do
442− res <- peekByteIndex i arr
451+ res <- peekAt i arr
443 return $ res /= (0 :: Int8)
452 return $ res /= (0 :: Int8)
444
453
445− {-# INLINE pokeByteIndex #-}
454+ {-# INLINE pokeAt #-}
446− pokeByteIndex i arr a =
455+ pokeAt i arr a =
447 if a
456 if a
448− then pokeByteIndex i arr (1 :: Int8)
457+ then pokeAt i arr (1 :: Int8)
449− else pokeByteIndex i arr (0 :: Int8)
458+ else pokeAt i arr (0 :: Int8)
450
459
451 {-# INLINE sizeOf #-}
460 {-# INLINE sizeOf #-}
452 sizeOf _ = 1
461 sizeOf _ = 1
@@ -489,7 +498,7 @@ readUnsafe = Peeker (Builder step)
489 ++ show next
498 ++ show next
490 ++ " end = " ++ show end
499 ++ " end = " ++ show end
491#endif
500#endif
492− r <- peekByteIndex pos arr
501+ r <- peekAt pos arr
493 return (r, BoundedPtr arr next end)
502 return (r, BoundedPtr arr next end)
494
503
495{-# INLINE read #-}
504{-# INLINE read #-}
@@ -506,7 +515,7 @@ read = Peeker (Builder step)
506 $ error $ "read: reading beyond limit. next = "
515 $ error $ "read: reading beyond limit. next = "
507 ++ show next
516 ++ show next
508 ++ " end = " ++ show end
517 ++ " end = " ++ show end
509− r <- peekByteIndex pos arr
518+ r <- peekAt pos arr
510 return (r, BoundedPtr arr next end)
519 return (r, BoundedPtr arr next end)
511
520
512{-# INLINE skipByte #-}
521{-# INLINE skipByte #-}
@@ -551,7 +560,7 @@ pokeBoundedPtrUnsafe a (BoundedPtr arr pos end) = do
551 ++ show next
560 ++ show next
552 ++ " end = " ++ show end
561 ++ " end = " ++ show end
553#endif
562#endif
554− pokeByteIndex pos arr a
563+ pokeAt pos arr a
555 return (BoundedPtr arr next end)
564 return (BoundedPtr arr next end)
556
565
557{-# INLINE pokeBoundedPtr #-}
566{-# INLINE pokeBoundedPtr #-}
@@ -559,7 +568,7 @@ pokeBoundedPtr :: forall a. Unbox a => a -> BoundedPtr -> IO BoundedPtr
559pokeBoundedPtr a (BoundedPtr arr pos end) = do
568pokeBoundedPtr a (BoundedPtr arr pos end) = do
560 let next = pos + sizeOf (Proxy :: Proxy a)
569 let next = pos + sizeOf (Proxy :: Proxy a)
561 when (next > end) $ error "pokeBoundedPtr writing beyond limit"
570 when (next > end) $ error "pokeBoundedPtr writing beyond limit"
562− pokeByteIndex pos arr a
571+ pokeAt pos arr a
563 return (BoundedPtr arr next end)
572 return (BoundedPtr arr next end)
564
573
565--------------------------------------------------------------------------------
574--------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/Unbox/TH.hs+8−8
@@ -252,7 +252,7 @@ mkPeekExprOne tagSize (DataCon cname _ _ fields) =
252
252
253 where
253 where
254
254
255− peekField i = [|peekByteIndex $(varE (mkOffsetName i)) $(varE _arr)|]
255+ peekField i = [|peekAt $(varE (mkOffsetName i)) $(varE _arr)|]
256
256
257mkPeekExpr :: Type -> [DataCon] -> Q Exp
257mkPeekExpr :: Type -> [DataCon] -> Q Exp
258mkPeekExpr headTy cons =
258mkPeekExpr headTy cons =
@@ -266,7 +266,7 @@ mkPeekExpr headTy cons =
266 doE
266 doE
267 [ bindS
267 [ bindS
268 (varP _tag)
268 (varP _tag)
269− [|peekByteIndex $(varE _initialOffset) $(varE _arr)|]
269+ [|peekAt $(varE _initialOffset) $(varE _arr)|]
270 , noBindS
270 , noBindS
271 (caseE
271 (caseE
272 (sigE (varE _tag) (conT tagType))
272 (sigE (varE _tag) (conT tagType))
@@ -299,7 +299,7 @@ mkPokeExprTag tagType tagVal = pokeTag
299 where
299 where
300
300
301 pokeTag =
301 pokeTag =
302− [|pokeByteIndex
302+ [|pokeAt
303 $(varE _initialOffset)
303 $(varE _initialOffset)
304 $(varE _arr)
304 $(varE _arr)
305 $((sigE (litE (IntegerL (fromIntegral tagVal))) (conT tagType)))|]
305 $((sigE (litE (IntegerL (fromIntegral tagVal))) (conT tagType)))|]
@@ -317,7 +317,7 @@ mkPokeExprFields tagSize fields = do
317
317
318 numFields = length fields
318 numFields = length fields
319 pokeField i =
319 pokeField i =
320− [|pokeByteIndex
320+ [|pokeAt
321 $(varE (mkOffsetName i))
321 $(varE (mkOffsetName i))
322 $(varE _arr)
322 $(varE _arr)
323 $(varE (mkFieldName i))|]
323 $(varE (mkFieldName i))|]
@@ -402,9 +402,9 @@ deriveUnboxInternal headTy cons mkDec = do
402 -- none
402 -- none
403 [ -- PragmaD (InlineP 'sizeOf Inline FunLike AllPhases)
403 [ -- PragmaD (InlineP 'sizeOf Inline FunLike AllPhases)
404 FunD 'sizeOf [Clause [WildP] (NormalB sizeOfMethod) []]
404 FunD 'sizeOf [Clause [WildP] (NormalB sizeOfMethod) []]
405− , PragmaD (InlineP 'peekByteIndex Inline FunLike AllPhases)
405+ , PragmaD (InlineP 'peekAt Inline FunLike AllPhases)
406 , FunD
406 , FunD
407− 'peekByteIndex
407+ 'peekAt
408 [ Clause
408 [ Clause
409 (if isUnitType cons
409 (if isUnitType cons
410 then [WildP, WildP]
410 then [WildP, WildP]
@@ -412,9 +412,9 @@ deriveUnboxInternal headTy cons mkDec = do
412 (NormalB peekMethod)
412 (NormalB peekMethod)
413 []
413 []
414 ]
414 ]
415− , PragmaD (InlineP 'pokeByteIndex Inline FunLike AllPhases)
415+ , PragmaD (InlineP 'pokeAt Inline FunLike AllPhases)
416 , FunD
416 , FunD
417− 'pokeByteIndex
417+ 'pokeAt
418 [ Clause
418 [ Clause
419 (if isUnitType cons
419 (if isUnitType cons
420 then [WildP, WildP, WildP]
420 then [WildP, WildP, WildP]
core/src/Streamly/Internal/Unicode/Stream.hs+3−3
@@ -116,7 +116,7 @@ import Streamly.Internal.Data.Stream (Stream)
116import Streamly.Internal.Data.Stream (Step (..))
116import Streamly.Internal.Data.Stream (Step (..))
117import Streamly.Internal.Data.SVar.Type (adaptState)
117import Streamly.Internal.Data.SVar.Type (adaptState)
118import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
118import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
119−import Streamly.Internal.Data.Unbox (Unbox(peekByteIndex))
119+import Streamly.Internal.Data.Unbox (Unbox(peekAt))
120import Streamly.Internal.Data.Unfold.Type (Unfold(..))
120import Streamly.Internal.Data.Unfold.Type (Unfold(..))
121import Streamly.Internal.System.IO (unsafeInlineIO)
121import Streamly.Internal.System.IO (unsafeInlineIO)
122
122
@@ -746,7 +746,7 @@ decodeUtf8ArraysWithD cfm (D.Stream step state) =
746 | p == end = do
746 | p == end = do
747 return $ Skip $ OuterLoop st Nothing
747 return $ Skip $ OuterLoop st Nothing
748 step' _ _ (InnerLoopDecodeInit st contents p end) = do
748 step' _ _ (InnerLoopDecodeInit st contents p end) = do
749− x <- liftIO $ peekByteIndex p contents
749+ x <- liftIO $ peekAt p contents
750 -- Note: It is important to use a ">" instead of a "<=" test here for
750 -- Note: It is important to use a ">" instead of a "<=" test here for
751 -- GHC to generate code layout for default branch prediction for the
751 -- GHC to generate code layout for default branch prediction for the
752 -- common case. This is fragile and might change with the compiler
752 -- common case. This is fragile and might change with the compiler
@@ -780,7 +780,7 @@ decodeUtf8ArraysWithD cfm (D.Stream step state) =
780 step' _ _ (InnerLoopDecoding st _ p end sv cp)
780 step' _ _ (InnerLoopDecoding st _ p end sv cp)
781 | p == end = return $ Skip $ OuterLoop st (Just (sv, cp))
781 | p == end = return $ Skip $ OuterLoop st (Just (sv, cp))
782 step' table _ (InnerLoopDecoding st contents p end statePtr codepointPtr) = do
782 step' table _ (InnerLoopDecoding st contents p end statePtr codepointPtr) = do
783− x <- liftIO $ peekByteIndex p contents
783+ x <- liftIO $ peekAt p contents
784 let (Tuple' sv cp) = decode1 table statePtr codepointPtr x
784 let (Tuple' sv cp) = decode1 table statePtr codepointPtr x
785 return $
785 return $
786 case sv of
786 case sv of
test/Streamly/Test/Data/Unbox.hs+8−8
@@ -46,8 +46,8 @@ import Test.Hspec as H
46
46
47#else
47#else
48
48
49−#define PEEK(i, arr, sz) peekByteIndexWithNextOff i arr
49+#define PEEK(i, arr, sz) peekAtWithNextOff i arr
50−#define POKE(i, arr, val) pokeByteIndexWithNextOff i arr val
50+#define POKE(i, arr, val) pokeAtWithNextOff i arr val
51#define TYPE_CLASS Unbox
51#define TYPE_CLASS Unbox
52
52
53#ifdef USE_TH
53#ifdef USE_TH
@@ -70,23 +70,23 @@ import Test.Hspec as H
70
70
71#ifndef USE_SERIALIZE
71#ifndef USE_SERIALIZE
72
72
73−peekByteIndexWithNextOff ::
73+peekAtWithNextOff ::
74 forall a. Unbox a
74 forall a. Unbox a
75 => Int
75 => Int
76 -> MutByteArray
76 -> MutByteArray
77 -> IO (Int, a)
77 -> IO (Int, a)
78−peekByteIndexWithNextOff i arr = do
78+peekAtWithNextOff i arr = do
79− val <- peekByteIndex i arr
79+ val <- peekAt i arr
80 pure (i + sizeOf (Proxy :: Proxy a), val)
80 pure (i + sizeOf (Proxy :: Proxy a), val)
81
81
82−pokeByteIndexWithNextOff ::
82+pokeAtWithNextOff ::
83 forall a. Unbox a
83 forall a. Unbox a
84 => Int
84 => Int
85 -> MutByteArray
85 -> MutByteArray
86 -> a
86 -> a
87 -> IO Int
87 -> IO Int
88−pokeByteIndexWithNextOff i arr val = do
88+pokeAtWithNextOff i arr val = do
89− pokeByteIndex i arr val
89+ pokeAt i arr val
90 pure $ i + sizeOf (Proxy :: Proxy a)
90 pure $ i + sizeOf (Proxy :: Proxy a)
91
91
92#endif
92#endif
test/Streamly/Test/Data/Unbox/TH.hs+2−2
@@ -30,8 +30,8 @@ testSerialization ::
30 -> IO ()
30 -> IO ()
31testSerialization val = do
31testSerialization val = do
32 arr <- MBA.new (sizeOf (Proxy :: Proxy a))
32 arr <- MBA.new (sizeOf (Proxy :: Proxy a))
33− pokeByteIndex 0 arr val
33+ pokeAt 0 arr val
34− peekByteIndex 0 arr `shouldReturn` val
34+ peekAt 0 arr `shouldReturn` val
35
35
36-- Size is also implicitly tested while serializing and deserializing.
36-- Size is also implicitly tested while serializing and deserializing.
37checkSizeOf :: forall a. Unbox a => Proxy a -> Int -> IO ()
37checkSizeOf :: forall a. Unbox a => Proxy a -> Int -> IO ()