From 64895d29c0f2a81da980f38cc103619c3917308d Mon Sep 17 00:00:00 2001 From: Adithya Kumar Date: Wed, 24 Jul 2024 03:54:25 +0530 Subject: [PATCH] Rename pokeAppend(May) to poke(May) in MutArray --- .../Streamly/Internal/Data/MutArray/Type.hs | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/core/src/Streamly/Internal/Data/MutArray/Type.hs b/core/src/Streamly/Internal/Data/MutArray/Type.hs index 2fe9fd942e..237707006d 100644 --- a/core/src/Streamly/Internal/Data/MutArray/Type.hs +++ b/core/src/Streamly/Internal/Data/MutArray/Type.hs @@ -213,8 +213,8 @@ module Streamly.Internal.Data.MutArray.Type -- , appendSliceFrom -- ** Serialization using Unbox - , pokeAppend - , pokeAppendMay + , poke + , pokeMay , unsafePokeSkip -- ** Deserialization using Unbox @@ -272,6 +272,8 @@ module Streamly.Internal.Data.MutArray.Type , createOfWith , peekUncons , peekUnconsUnsafe + , pokeAppend + , pokeAppendMay , castUnsafe , newArrayWith , getSliceUnsafe @@ -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. @@ -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 @@ -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 @@ -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 @@ -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