on master help sign in
Rename newBytes and pinnedNewBytes
commit627c72ae6529198d6b4c653c7607a8c7dfacc390 authorHarendra Kumar <harendra@composewell.com> dateFri 24 Nov 2023, 13:10 (3 years ago) parent47b10b3
7 files changed+31−31
benchmark/Streamly/Benchmark/Data/Serialize.hs+5−5 core/src/Streamly/Internal/Data/IORef/Unboxed.hs+2−2 core/src/Streamly/Internal/Data/MutArray/Type.hs+4−4 core/src/Streamly/Internal/Data/Unbox.hs+15−15 test/Streamly/Test/Data/Serialize.hs+2−2 test/Streamly/Test/Data/Unbox.hs+2−2 test/Streamly/Test/Data/Unbox/TH.hs+1−1
benchmark/Streamly/Benchmark/Data/Serialize.hs+5−5
@@ -335,7 +335,7 @@ pokeWithSize arr val = do
335335pokeTimesWithSize :: SERIALIZE_CLASS a => a -> Int -> IO ()
336336pokeTimesWithSize val times = do
337337 let n = getSize val
338− arr <- newBytes n
338+ arr <- newByteArray n
339339 loopWith times pokeWithSize arr val
340340-}
341341
@@ -347,14 +347,14 @@ poke arr val = SERIALIZE_OP 0 arr val >> return ()
347347pokeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
348348pokeTimes val times = do
349349 let n = getSize val
350− arr <- newBytes n
350+ arr <- newByteArray n
351351 loopWith times poke arr val
352352
353353{-# INLINE encode #-}
354354encode :: SERIALIZE_CLASS a => a -> IO ()
355355encode val = do
356356 let n = getSize val
357− arr <- newBytes n
357+ arr <- newByteArray n
358358 SERIALIZE_OP 0 arr val >> return ()
359359
360360{-# INLINE encodeTimes #-}
@@ -390,7 +390,7 @@ peek (_val, n) arr = do
390390{-# INLINE peekTimes #-}
391391peekTimes :: (NFData a, SERIALIZE_CLASS a) => Int -> a -> Int -> IO ()
392392peekTimes n val times = do
393− arr <- newBytes n
393+ arr <- newByteArray n
394394 _ <- SERIALIZE_OP 0 arr val
395395 loopWith times peek (val, n) arr
396396
@@ -398,7 +398,7 @@ peekTimes n val times = do
398398trip :: forall a. (NFData a, SERIALIZE_CLASS a) => a -> IO ()
399399trip val = do
400400 let n = getSize val
401− arr <- newBytes n
401+ arr <- newByteArray n
402402 _ <- SERIALIZE_OP 0 arr val
403403#ifdef USE_UNBOX
404404 (val1 :: a) <- DESERIALIZE_OP 0 arr
core/src/Streamly/Internal/Data/IORef/Unboxed.hs+2−2
@@ -43,7 +43,7 @@ import Control.Monad.IO.Class (MonadIO(..))
4343import Streamly.Internal.Data.Unbox
4444 ( MutByteArray(..)
4545 , Unbox(..)
46− , newBytes
46+ , newByteArray
4747 , sizeOf
4848 )
4949
@@ -58,7 +58,7 @@ newtype IORef a = IORef MutByteArray
5858{-# INLINE newIORef #-}
5959newIORef :: forall a. Unbox a => a -> IO (IORef a)
6060newIORef x = do
61− var <- newBytes (sizeOf (Proxy :: Proxy a))
61+ var <- newByteArray (sizeOf (Proxy :: Proxy a))
6262 pokeByteIndex 0 var x
6363 return $ IORef var
6464
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.pinnedNewBytes newCapMaxInBytes
748− else Unboxed.newBytes newCapMaxInBytes
747+ then Unboxed.pinnedNewByteArray newCapMaxInBytes
748+ else Unboxed.newByteArray 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.pinnedNewBytes newLen
2138− else Unboxed.newBytes newLen
2137+ then Unboxed.pinnedNewByteArray newLen
2138+ else Unboxed.newByteArray 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/Unbox.hs+15−15
@@ -28,8 +28,8 @@ module Streamly.Internal.Data.Unbox
2828 , pin
2929 , unpin
3030 , newBytesAs
31− , newBytes
32− , pinnedNewBytes
31+ , newByteArray
32+ , pinnedNewByteArray
3333 , pinnedNewAlignedBytes
3434
3535 -- ** Unbox type class
@@ -167,23 +167,23 @@ asPtrUnsafe arr f = do
167167
168168{-# NOINLINE nil #-}
169169nil :: MutByteArray
170−nil = unsafePerformIO $ newBytes 0
170+nil = unsafePerformIO $ newByteArray 0
171171
172−{-# INLINE newBytes #-}
173−newBytes :: Int -> IO MutByteArray
174−newBytes nbytes | nbytes < 0 =
175− errorWithoutStackTrace "newBytes: size must be >= 0"
176−newBytes (I# nbytes) = IO $ \s ->
172+{-# INLINE newByteArray #-}
173+newByteArray :: Int -> IO MutByteArray
174+newByteArray nbytes | nbytes < 0 =
175+ errorWithoutStackTrace "newByteArray: size must be >= 0"
176+newByteArray (I# nbytes) = IO $ \s ->
177177 case newByteArray# nbytes s of
178178 (# s', mbarr# #) ->
179179 let c = MutByteArray mbarr#
180180 in (# s', c #)
181181
182−{-# INLINE pinnedNewBytes #-}
183−pinnedNewBytes :: Int -> IO MutByteArray
184−pinnedNewBytes nbytes | nbytes < 0 =
185− errorWithoutStackTrace "pinnedNewBytes: size must be >= 0"
186−pinnedNewBytes (I# nbytes) = IO $ \s ->
182+{-# INLINE pinnedNewByteArray #-}
183+pinnedNewByteArray :: Int -> IO MutByteArray
184+pinnedNewByteArray nbytes | nbytes < 0 =
185+ errorWithoutStackTrace "pinnedNewByteArray: size must be >= 0"
186+pinnedNewByteArray (I# nbytes) = IO $ \s ->
187187 case newPinnedByteArray# nbytes s of
188188 (# s', mbarr# #) ->
189189 let c = MutByteArray mbarr#
@@ -201,8 +201,8 @@ pinnedNewAlignedBytes (I# nbytes) (I# align) = IO $ \s ->
201201
202202{-# INLINE newBytesAs #-}
203203newBytesAs :: PinnedState -> Int -> IO MutByteArray
204−newBytesAs Unpinned = newBytes
205−newBytesAs Pinned = pinnedNewBytes
204+newBytesAs Unpinned = newByteArray
205+newBytesAs Pinned = pinnedNewByteArray
206206
207207-------------------------------------------------------------------------------
208208-- 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.Serialize (MutByteArray, newBytes)
25+import Streamly.Internal.Data.Serialize (MutByteArray, newByteArray)
2626import GHC.Generics (Generic)
2727import Streamly.Data.Serialize (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 <- newBytes arrSize
172+ arr <- newByteArray arrSize
173173
174174 off1 <- Serialize.serialize serStartOff arr val
175175 off1 `shouldBe` serEndOff
test/Streamly/Test/Data/Unbox.hs+2−2
@@ -198,7 +198,7 @@ testSerialization val = do
198198#else
199199 (sizeOf (Proxy :: Proxy a))
200200#endif
201− arr <- newBytes len
201+ arr <- newByteArray len
202202 nextOff <- POKE(0, arr, val)
203203 (nextOff1, val1) <- PEEK(0, arr, len)
204204 val1 `shouldBe` val
@@ -232,7 +232,7 @@ testGenericConsistency val = do
232232 len `shouldBe` genericSizeOf (Proxy :: Proxy a)
233233
234234 -- Test the serialization and deserialization
235− arr <- newBytes (sizeOf (Proxy :: Proxy a))
235+ arr <- newByteArray (sizeOf (Proxy :: Proxy a))
236236
237237 nextOff <- POKE(0, arr, val)
238238 genericPeekByteIndex arr 0 `shouldReturn` val
test/Streamly/Test/Data/Unbox/TH.hs+1−1
@@ -28,7 +28,7 @@ testSerialization ::
2828 => a
2929 -> IO ()
3030testSerialization val = do
31− arr <- newBytes (sizeOf (Proxy :: Proxy a))
31+ arr <- newByteArray (sizeOf (Proxy :: Proxy a))
3232 pokeByteIndex 0 arr val
3333 peekByteIndex 0 arr `shouldReturn` val
3434