Skip to content

Commit

Permalink
Rename pokeAppend(May) to poke(May) in MutArray
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Jul 23, 2024
1 parent a5dffc2 commit 64895d2
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions core/src/Streamly/Internal/Data/MutArray/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ module Streamly.Internal.Data.MutArray.Type
-- , appendSliceFrom

-- ** Serialization using Unbox
, pokeAppend
, pokeAppendMay
, poke
, pokeMay
, unsafePokeSkip

-- ** Deserialization using Unbox
Expand Down Expand Up @@ -272,6 +272,8 @@ module Streamly.Internal.Data.MutArray.Type
, createOfWith
, peekUncons
, peekUnconsUnsafe
, pokeAppend
, pokeAppendMay
, castUnsafe
, newArrayWith
, getSliceUnsafe
Expand Down Expand Up @@ -1152,10 +1154,10 @@ pokeNewEnd newEnd arr@MutArray{..} x = liftIO $ do
-- element.
--
-- /Internal/
{-# INLINE pokeAppendUnsafe #-}
pokeAppendUnsafe :: forall m a. (MonadIO m, Unbox a) =>
{-# INLINE unsafePoke #-}
unsafePoke :: forall m a. (MonadIO m, Unbox a) =>
MutArray Word8 -> a -> m (MutArray Word8)
pokeAppendUnsafe arr@MutArray{..} = pokeNewEnd (arrEnd + SIZE_OF(a)) arr
unsafePoke arr@MutArray{..} = pokeNewEnd (arrEnd + SIZE_OF(a)) arr

-- | Skip the specified number of bytes in the array. The data in the skipped
-- region remains uninitialzed.
Expand All @@ -1165,14 +1167,14 @@ unsafePokeSkip n arr@MutArray{..} = do
let newEnd = arrEnd + n
in assert (newEnd <= arrBound) (arr {arrEnd = newEnd})

-- | Like 'pokeAppend' but does not grow the array when pre-allocated array
-- | Like 'poke' but does not grow the array when pre-allocated array
-- capacity becomes full.
--
-- /Internal/
{-# INLINE pokeAppendMay #-}
pokeAppendMay :: forall m a. (MonadIO m, Unbox a) =>
{-# INLINE pokeMay #-}
pokeAppendMay, pokeMay :: forall m a. (MonadIO m, Unbox a) =>
MutArray Word8 -> a -> m (Maybe (MutArray Word8))
pokeAppendMay arr@MutArray{..} x = liftIO $ do
pokeMay arr@MutArray{..} x = liftIO $ do
let newEnd = arrEnd + SIZE_OF(a)
if newEnd <= arrBound
then Just <$> pokeNewEnd newEnd arr x
Expand All @@ -1186,15 +1188,15 @@ pokeWithRealloc :: forall m a. (MonadIO m, Unbox a) =>
-> m (MutArray Word8)
pokeWithRealloc sizer arr x = do
arr1 <- liftIO $ reallocBytesWith "pokeWithRealloc" sizer (SIZE_OF(a)) arr
pokeAppendUnsafe arr1 x
unsafePoke arr1 x

{-# INLINE pokeAppendWith #-}
pokeAppendWith :: forall m a. (MonadIO m, Unbox a) =>
{-# INLINE pokeWith #-}
pokeWith :: forall m a. (MonadIO m, Unbox a) =>
(Int -> Int)
-> MutArray Word8
-> a
-> m (MutArray Word8)
pokeAppendWith allocSize arr x = liftIO $ do
pokeWith allocSize arr x = liftIO $ do
let newEnd = arrEnd arr + SIZE_OF(a)
if newEnd <= arrBound arr
then pokeNewEnd newEnd arr x
Expand All @@ -1205,12 +1207,12 @@ pokeAppendWith allocSize arr x = liftIO $ do
--
-- Definition:
--
-- >>> pokeAppend arr x = MutArray.unsafeCast <$> MutArray.snoc (MutArray.unsafeCast arr) x
-- >>> poke arr x = MutArray.unsafeCast <$> MutArray.snoc (MutArray.unsafeCast arr) x
--
{-# INLINE pokeAppend #-}
pokeAppend :: forall m a. (MonadIO m, Unbox a) =>
{-# INLINE poke #-}
pokeAppend, poke :: forall m a. (MonadIO m, Unbox a) =>
MutArray Word8 -> a -> m (MutArray Word8)
pokeAppend = pokeAppendWith f
poke = pokeWith f

where

Expand Down Expand Up @@ -3384,6 +3386,8 @@ RENAME(pokeSkipUnsafe, unsafePokeSkip)
RENAME(peekSkipUnsafe, unsafePeekSkip)
RENAME(peekUncons, peek)
RENAME(peekUnconsUnsafe, unsafePeek)
RENAME(pokeAppend, poke)
RENAME(pokeAppendMay, pokeMay)

-- This renaming can be done directly without deprecations. But I'm keeping this
-- intentionally. Packdiff should be able to point out such APIs that we can
Expand Down

0 comments on commit 64895d2

Please sign in to comment.