on master help sign in
Rename newByteArray to new

To keep it consistent with naming in other Array modules.

commit56fd008519c131796dfbe811c9aa67ec931da5df authorHarendra Kumar <harendra@composewell.com> dateSat 25 Nov 2023, 09:39 (3 years ago) parent6705ec0
8 files changed+35−32
benchmark/Streamly/Benchmark/Data/Serialize.hs+6−5 core/src/Streamly/Data/MutByteArray.hs+2−2 core/src/Streamly/Internal/Data/IORef/Unboxed.hs+3−3 core/src/Streamly/Internal/Data/MutArray/Type.hs+4−4 core/src/Streamly/Internal/Data/MutByteArray/Type.hs+13−13 test/Streamly/Test/Data/Serialize.hs+2−2 test/Streamly/Test/Data/Unbox.hs+3−2 test/Streamly/Test/Data/Unbox/TH.hs+2−1
benchmark/Streamly/Benchmark/Data/Serialize.hs+6−5
@@ -25,6 +25,7 @@ import Test.QuickCheck (Arbitrary, arbitrary)
2525#endif
2626
2727import Streamly.Internal.Data.MutByteArray hiding (encode)
28+import qualified Streamly.Internal.Data.MutByteArray as MBA
2829#ifdef USE_UNBOX
2930import Data.Proxy (Proxy(..))
3031#else
@@ -335,7 +336,7 @@ pokeWithSize arr val = do
335336pokeTimesWithSize :: SERIALIZE_CLASS a => a -> Int -> IO ()
336337pokeTimesWithSize val times = do
337338 let n = getSize val
338− arr <- newByteArray n
339+ arr <- MBA.new n
339340 loopWith times pokeWithSize arr val
340341-}
341342
@@ -347,14 +348,14 @@ poke arr val = SERIALIZE_OP 0 arr val >> return ()
347348pokeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
348349pokeTimes val times = do
349350 let n = getSize val
350− arr <- newByteArray n
351+ arr <- MBA.new n
351352 loopWith times poke arr val
352353
353354{-# INLINE encode #-}
354355encode :: SERIALIZE_CLASS a => a -> IO ()
355356encode val = do
356357 let n = getSize val
357− arr <- newByteArray n
358+ arr <- MBA.new n
358359 SERIALIZE_OP 0 arr val >> return ()
359360
360361{-# INLINE encodeTimes #-}
@@ -390,7 +391,7 @@ peek (_val, n) arr = do
390391{-# INLINE peekTimes #-}
391392peekTimes :: (NFData a, SERIALIZE_CLASS a) => Int -> a -> Int -> IO ()
392393peekTimes n val times = do
393− arr <- newByteArray n
394+ arr <- MBA.new n
394395 _ <- SERIALIZE_OP 0 arr val
395396 loopWith times peek (val, n) arr
396397
@@ -398,7 +399,7 @@ peekTimes n val times = do
398399trip :: forall a. (NFData a, SERIALIZE_CLASS a) => a -> IO ()
399400trip val = do
400401 let n = getSize val
401− arr <- newByteArray n
402+ arr <- MBA.new n
402403 _ <- SERIALIZE_OP 0 arr val
403404#ifdef USE_UNBOX
404405 (val1 :: a) <- DESERIALIZE_OP 0 arr
core/src/Streamly/Data/MutByteArray.hs+2−2
@@ -52,8 +52,8 @@ module Streamly.Data.MutByteArray
5252 , isPinned
5353 , pin
5454 , unpin
55− , newByteArray
56− , pinnedNewByteArray
55+ , new
56+ , pinnedNew
5757
5858 -- * Unbox
5959 , Unbox(..)
core/src/Streamly/Internal/Data/IORef/Unboxed.hs+3−3
@@ -40,10 +40,10 @@ where
4040
4141import Control.Monad.IO.Class (MonadIO(..))
4242import Data.Proxy (Proxy(..))
43−import Streamly.Internal.Data.MutByteArray.Type
44− (MutByteArray(..), newByteArray)
43+import Streamly.Internal.Data.MutByteArray.Type (MutByteArray)
4544import Streamly.Internal.Data.Unbox (Unbox(..), sizeOf)
4645
46+import qualified Streamly.Internal.Data.MutByteArray.Type as MBA
4747import qualified Streamly.Internal.Data.Stream.Type as D
4848
4949-- | An 'IORef' holds a single 'Unbox'-able value.
@@ -55,7 +55,7 @@ newtype IORef a = IORef MutByteArray
5555{-# INLINE newIORef #-}
5656newIORef :: forall a. Unbox a => a -> IO (IORef a)
5757newIORef x = do
58− var <- newByteArray (sizeOf (Proxy :: Proxy a))
58+ var <- MBA.new (sizeOf (Proxy :: Proxy a))
5959 pokeByteIndex 0 var x
6060 return $ IORef var
6161
core/src/Streamly/Internal/Data/MutArray/Type.hs+4−4
@@ -744,8 +744,8 @@ reallocExplicit elemSize newCapacityInBytes MutArray{..} = do
744744 let newCapMaxInBytes = roundUpLargeArray newCapacityInBytes
745745 contents <-
746746 if Unboxed.isPinned arrContents
747− then Unboxed.pinnedNewByteArray newCapMaxInBytes
748− else Unboxed.newByteArray newCapMaxInBytes
747+ then Unboxed.pinnedNew newCapMaxInBytes
748+ else Unboxed.new newCapMaxInBytes
749749 let !(MutByteArray mbarrFrom#) = arrContents
750750 !(MutByteArray mbarrTo#) = contents
751751
@@ -2134,8 +2134,8 @@ spliceCopy arr1 arr2 = liftIO $ do
21342134 let newLen = len1 + len2
21352135 newArrContents <-
21362136 if Unboxed.isPinned (arrContents arr1)
2137− then Unboxed.pinnedNewByteArray newLen
2138− else Unboxed.newByteArray newLen
2137+ then Unboxed.pinnedNew newLen
2138+ else Unboxed.new newLen
21392139 let len = len1 + len2
21402140 putSliceUnsafe (arrContents arr1) start1 newArrContents 0 len1
21412141 putSliceUnsafe (arrContents arr2) start2 newArrContents len1 len2
core/src/Streamly/Internal/Data/MutByteArray/Type.hs+13−13
@@ -24,8 +24,8 @@ module Streamly.Internal.Data.MutByteArray.Type
2424 -- ** Allocation
2525 , nil
2626 , newBytesAs
27− , newByteArray
28− , pinnedNewByteArray
27+ , new
28+ , pinnedNew
2929 , pinnedNewAlignedBytes
3030
3131 -- ** Access
@@ -122,23 +122,23 @@ asPtrUnsafe arr f = do
122122
123123{-# NOINLINE nil #-}
124124nil :: MutByteArray
125−nil = unsafePerformIO $ newByteArray 0
125+nil = unsafePerformIO $ new 0
126126
127−{-# INLINE newByteArray #-}
128−newByteArray :: Int -> IO MutByteArray
129−newByteArray nbytes | nbytes < 0 =
127+{-# INLINE new #-}
128+new :: Int -> IO MutByteArray
129+new nbytes | nbytes < 0 =
130130 errorWithoutStackTrace "newByteArray: size must be >= 0"
131−newByteArray (I# nbytes) = IO $ \s ->
131+new (I# nbytes) = IO $ \s ->
132132 case newByteArray# nbytes s of
133133 (# s', mbarr# #) ->
134134 let c = MutByteArray mbarr#
135135 in (# s', c #)
136136
137−{-# INLINE pinnedNewByteArray #-}
138−pinnedNewByteArray :: Int -> IO MutByteArray
139−pinnedNewByteArray nbytes | nbytes < 0 =
137+{-# INLINE pinnedNew #-}
138+pinnedNew :: Int -> IO MutByteArray
139+pinnedNew nbytes | nbytes < 0 =
140140 errorWithoutStackTrace "pinnedNewByteArray: size must be >= 0"
141−pinnedNewByteArray (I# nbytes) = IO $ \s ->
141+pinnedNew (I# nbytes) = IO $ \s ->
142142 case newPinnedByteArray# nbytes s of
143143 (# s', mbarr# #) ->
144144 let c = MutByteArray mbarr#
@@ -156,8 +156,8 @@ pinnedNewAlignedBytes (I# nbytes) (I# align) = IO $ \s ->
156156
157157{-# INLINE newBytesAs #-}
158158newBytesAs :: PinnedState -> Int -> IO MutByteArray
159−newBytesAs Unpinned = newByteArray
160−newBytesAs Pinned = pinnedNewByteArray
159+newBytesAs Unpinned = new
160+newBytesAs Pinned = pinnedNew
161161
162162-------------------------------------------------------------------------------
163163-- Copying
test/Streamly/Test/Data/Serialize.hs+2−2
@@ -22,7 +22,7 @@ module Streamly.Test.Data.Serialize (main) where
2222--------------------------------------------------------------------------------
2323
2424import System.Random (randomRIO)
25−import Streamly.Internal.Data.MutByteArray (MutByteArray, newByteArray)
25+import Streamly.Internal.Data.MutByteArray (MutByteArray)
2626import GHC.Generics (Generic)
2727import Streamly.Data.MutByteArray (Serialize)
2828import Streamly.Test.Data.Serialize.TH (genDatatype)
@@ -169,7 +169,7 @@ poke val = do
169169 let arrSize = sz + excessSize
170170 serStartOff = randomOff
171171 serEndOff = randomOff + sz
172− arr <- newByteArray arrSize
172+ arr <- Serialize.new arrSize
173173
174174 off1 <- Serialize.serialize serStartOff arr val
175175 off1 `shouldBe` serEndOff
test/Streamly/Test/Data/Unbox.hs+3−2
@@ -28,6 +28,7 @@ import GHC.Generics (Generic, Rep(..))
2828import GHC.Real (Ratio(..))
2929
3030import Streamly.Internal.Data.MutByteArray
31+import qualified Streamly.Internal.Data.MutByteArray as MBA
3132
3233import Test.Hspec as H
3334
@@ -198,7 +199,7 @@ testSerialization val = do
198199#else
199200 (sizeOf (Proxy :: Proxy a))
200201#endif
201− arr <- newByteArray len
202+ arr <- MBA.new len
202203 nextOff <- POKE(0, arr, val)
203204 (nextOff1, val1) <- PEEK(0, arr, len)
204205 val1 `shouldBe` val
@@ -232,7 +233,7 @@ testGenericConsistency val = do
232233 len `shouldBe` genericSizeOf (Proxy :: Proxy a)
233234
234235 -- Test the serialization and deserialization
235− arr <- newByteArray (sizeOf (Proxy :: Proxy a))
236+ arr <- MBA.new (sizeOf (Proxy :: Proxy a))
236237
237238 nextOff <- POKE(0, arr, val)
238239 genericPeekByteIndex arr 0 `shouldReturn` val
test/Streamly/Test/Data/Unbox/TH.hs+2−1
@@ -16,6 +16,7 @@ module Streamly.Test.Data.Unbox.TH (main) where
1616
1717import Data.Proxy (Proxy(..))
1818import Streamly.Internal.Data.MutByteArray
19+import qualified Streamly.Internal.Data.MutByteArray as MBA
1920
2021import Test.Hspec as H
2122
@@ -28,7 +29,7 @@ testSerialization ::
2829 => a
2930 -> IO ()
3031testSerialization val = do
31− arr <- newByteArray (sizeOf (Proxy :: Proxy a))
32+ arr <- MBA.new (sizeOf (Proxy :: Proxy a))
3233 pokeByteIndex 0 arr val
3334 peekByteIndex 0 arr `shouldReturn` val
3435