on master help sign in
Rename newBytes and pinnedNewBytes
627c72aHarendra Kumar
benchmark/Streamly/Benchmark/Data/Serialize.hs+5−5
@@ -335,7 +335,7 @@ pokeWithSize arr val = do
335pokeTimesWithSize :: SERIALIZE_CLASS a => a -> Int -> IO ()
335pokeTimesWithSize :: SERIALIZE_CLASS a => a -> Int -> IO ()
336pokeTimesWithSize val times = do
336pokeTimesWithSize val times = do
337 let n = getSize val
337 let n = getSize val
338− arr <- newBytes n
338+ arr <- newByteArray n
339 loopWith times pokeWithSize arr val
339 loopWith times pokeWithSize arr val
340-}
340-}
341
341
@@ -347,14 +347,14 @@ poke arr val = SERIALIZE_OP 0 arr val >> return ()
347pokeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
347pokeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
348pokeTimes val times = do
348pokeTimes val times = do
349 let n = getSize val
349 let n = getSize val
350− arr <- newBytes n
350+ arr <- newByteArray n
351 loopWith times poke arr val
351 loopWith times poke arr val
352
352
353{-# INLINE encode #-}
353{-# INLINE encode #-}
354encode :: SERIALIZE_CLASS a => a -> IO ()
354encode :: SERIALIZE_CLASS a => a -> IO ()
355encode val = do
355encode val = do
356 let n = getSize val
356 let n = getSize val
357− arr <- newBytes n
357+ arr <- newByteArray n
358 SERIALIZE_OP 0 arr val >> return ()
358 SERIALIZE_OP 0 arr val >> return ()
359
359
360{-# INLINE encodeTimes #-}
360{-# INLINE encodeTimes #-}
@@ -390,7 +390,7 @@ peek (_val, n) arr = do
390{-# INLINE peekTimes #-}
390{-# INLINE peekTimes #-}
391peekTimes :: (NFData a, SERIALIZE_CLASS a) => Int -> a -> Int -> IO ()
391peekTimes :: (NFData a, SERIALIZE_CLASS a) => Int -> a -> Int -> IO ()
392peekTimes n val times = do
392peekTimes n val times = do
393− arr <- newBytes n
393+ arr <- newByteArray n
394 _ <- SERIALIZE_OP 0 arr val
394 _ <- SERIALIZE_OP 0 arr val
395 loopWith times peek (val, n) arr
395 loopWith times peek (val, n) arr
396
396
@@ -398,7 +398,7 @@ peekTimes n val times = do
398trip :: forall a. (NFData a, SERIALIZE_CLASS a) => a -> IO ()
398trip :: forall a. (NFData a, SERIALIZE_CLASS a) => a -> IO ()
399trip val = do
399trip val = do
400 let n = getSize val
400 let n = getSize val
401− arr <- newBytes n
401+ arr <- newByteArray n
402 _ <- SERIALIZE_OP 0 arr val
402 _ <- SERIALIZE_OP 0 arr val
403#ifdef USE_UNBOX
403#ifdef USE_UNBOX
404 (val1 :: a) <- DESERIALIZE_OP 0 arr
404 (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(..))
43import Streamly.Internal.Data.Unbox
43import Streamly.Internal.Data.Unbox
44 ( MutByteArray(..)
44 ( MutByteArray(..)
45 , Unbox(..)
45 , Unbox(..)
46− , newBytes
46+ , newByteArray
47 , sizeOf
47 , sizeOf
48 )
48 )
49
49
@@ -58,7 +58,7 @@ newtype IORef a = IORef MutByteArray
58{-# INLINE newIORef #-}
58{-# INLINE newIORef #-}
59newIORef :: forall a. Unbox a => a -> IO (IORef a)
59newIORef :: forall a. Unbox a => a -> IO (IORef a)
60newIORef x = do
60newIORef x = do
61− var <- newBytes (sizeOf (Proxy :: Proxy a))
61+ var <- newByteArray (sizeOf (Proxy :: Proxy a))
62 pokeByteIndex 0 var x
62 pokeByteIndex 0 var x
63 return $ IORef var
63 return $ IORef var
64
64
core/src/Streamly/Internal/Data/MutArray/Type.hs+4−4
@@ -744,8 +744,8 @@ reallocExplicit elemSize newCapacityInBytes MutArray{..} = do
744 let newCapMaxInBytes = roundUpLargeArray newCapacityInBytes
744 let newCapMaxInBytes = roundUpLargeArray newCapacityInBytes
745 contents <-
745 contents <-
746 if Unboxed.isPinned arrContents
746 if Unboxed.isPinned arrContents
747− then Unboxed.pinnedNewBytes newCapMaxInBytes
747+ then Unboxed.pinnedNewByteArray newCapMaxInBytes
748− else Unboxed.newBytes newCapMaxInBytes
748+ else Unboxed.newByteArray newCapMaxInBytes
749 let !(MutByteArray mbarrFrom#) = arrContents
749 let !(MutByteArray mbarrFrom#) = arrContents
750 !(MutByteArray mbarrTo#) = contents
750 !(MutByteArray mbarrTo#) = contents
751
751
@@ -2134,8 +2134,8 @@ spliceCopy arr1 arr2 = liftIO $ do
2134 let newLen = len1 + len2
2134 let newLen = len1 + len2
2135 newArrContents <-
2135 newArrContents <-
2136 if Unboxed.isPinned (arrContents arr1)
2136 if Unboxed.isPinned (arrContents arr1)
2137− then Unboxed.pinnedNewBytes newLen
2137+ then Unboxed.pinnedNewByteArray newLen
2138− else Unboxed.newBytes newLen
2138+ else Unboxed.newByteArray newLen
2139 let len = len1 + len2
2139 let len = len1 + len2
2140 putSliceUnsafe (arrContents arr1) start1 newArrContents 0 len1
2140 putSliceUnsafe (arrContents arr1) start1 newArrContents 0 len1
2141 putSliceUnsafe (arrContents arr2) start2 newArrContents len1 len2
2141 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
28 , pin
28 , pin
29 , unpin
29 , unpin
30 , newBytesAs
30 , newBytesAs
31− , newBytes
31+ , newByteArray
32− , pinnedNewBytes
32+ , pinnedNewByteArray
33 , pinnedNewAlignedBytes
33 , pinnedNewAlignedBytes
34
34
35 -- ** Unbox type class
35 -- ** Unbox type class
@@ -167,23 +167,23 @@ asPtrUnsafe arr f = do
167
167
168{-# NOINLINE nil #-}
168{-# NOINLINE nil #-}
169nil :: MutByteArray
169nil :: MutByteArray
170−nil = unsafePerformIO $ newBytes 0
170+nil = unsafePerformIO $ newByteArray 0
171
171
172−{-# INLINE newBytes #-}
172+{-# INLINE newByteArray #-}
173−newBytes :: Int -> IO MutByteArray
173+newByteArray :: Int -> IO MutByteArray
174−newBytes nbytes | nbytes < 0 =
174+newByteArray nbytes | nbytes < 0 =
175− errorWithoutStackTrace "newBytes: size must be >= 0"
175+ errorWithoutStackTrace "newByteArray: size must be >= 0"
176−newBytes (I# nbytes) = IO $ \s ->
176+newByteArray (I# nbytes) = IO $ \s ->
177 case newByteArray# nbytes s of
177 case newByteArray# nbytes s of
178 (# s', mbarr# #) ->
178 (# s', mbarr# #) ->
179 let c = MutByteArray mbarr#
179 let c = MutByteArray mbarr#
180 in (# s', c #)
180 in (# s', c #)
181
181
182−{-# INLINE pinnedNewBytes #-}
182+{-# INLINE pinnedNewByteArray #-}
183−pinnedNewBytes :: Int -> IO MutByteArray
183+pinnedNewByteArray :: Int -> IO MutByteArray
184−pinnedNewBytes nbytes | nbytes < 0 =
184+pinnedNewByteArray nbytes | nbytes < 0 =
185− errorWithoutStackTrace "pinnedNewBytes: size must be >= 0"
185+ errorWithoutStackTrace "pinnedNewByteArray: size must be >= 0"
186−pinnedNewBytes (I# nbytes) = IO $ \s ->
186+pinnedNewByteArray (I# nbytes) = IO $ \s ->
187 case newPinnedByteArray# nbytes s of
187 case newPinnedByteArray# nbytes s of
188 (# s', mbarr# #) ->
188 (# s', mbarr# #) ->
189 let c = MutByteArray mbarr#
189 let c = MutByteArray mbarr#
@@ -201,8 +201,8 @@ pinnedNewAlignedBytes (I# nbytes) (I# align) = IO $ \s ->
201
201
202{-# INLINE newBytesAs #-}
202{-# INLINE newBytesAs #-}
203newBytesAs :: PinnedState -> Int -> IO MutByteArray
203newBytesAs :: PinnedState -> Int -> IO MutByteArray
204−newBytesAs Unpinned = newBytes
204+newBytesAs Unpinned = newByteArray
205−newBytesAs Pinned = pinnedNewBytes
205+newBytesAs Pinned = pinnedNewByteArray
206
206
207-------------------------------------------------------------------------------
207-------------------------------------------------------------------------------
208-- Copying
208-- Copying
test/Streamly/Test/Data/Serialize.hs+2−2
@@ -22,7 +22,7 @@ module Streamly.Test.Data.Serialize (main) where
22--------------------------------------------------------------------------------
22--------------------------------------------------------------------------------
23
23
24import System.Random (randomRIO)
24import System.Random (randomRIO)
25−import Streamly.Internal.Data.Serialize (MutByteArray, newBytes)
25+import Streamly.Internal.Data.Serialize (MutByteArray, newByteArray)
26import GHC.Generics (Generic)
26import GHC.Generics (Generic)
27import Streamly.Data.Serialize (Serialize)
27import Streamly.Data.Serialize (Serialize)
28import Streamly.Test.Data.Serialize.TH (genDatatype)
28import Streamly.Test.Data.Serialize.TH (genDatatype)
@@ -169,7 +169,7 @@ poke val = do
169 let arrSize = sz + excessSize
169 let arrSize = sz + excessSize
170 serStartOff = randomOff
170 serStartOff = randomOff
171 serEndOff = randomOff + sz
171 serEndOff = randomOff + sz
172− arr <- newBytes arrSize
172+ arr <- newByteArray arrSize
173
173
174 off1 <- Serialize.serialize serStartOff arr val
174 off1 <- Serialize.serialize serStartOff arr val
175 off1 `shouldBe` serEndOff
175 off1 `shouldBe` serEndOff
test/Streamly/Test/Data/Unbox.hs+2−2
@@ -198,7 +198,7 @@ testSerialization val = do
198#else
198#else
199 (sizeOf (Proxy :: Proxy a))
199 (sizeOf (Proxy :: Proxy a))
200#endif
200#endif
201− arr <- newBytes len
201+ arr <- newByteArray len
202 nextOff <- POKE(0, arr, val)
202 nextOff <- POKE(0, arr, val)
203 (nextOff1, val1) <- PEEK(0, arr, len)
203 (nextOff1, val1) <- PEEK(0, arr, len)
204 val1 `shouldBe` val
204 val1 `shouldBe` val
@@ -232,7 +232,7 @@ testGenericConsistency val = do
232 len `shouldBe` genericSizeOf (Proxy :: Proxy a)
232 len `shouldBe` genericSizeOf (Proxy :: Proxy a)
233
233
234 -- Test the serialization and deserialization
234 -- Test the serialization and deserialization
235− arr <- newBytes (sizeOf (Proxy :: Proxy a))
235+ arr <- newByteArray (sizeOf (Proxy :: Proxy a))
236
236
237 nextOff <- POKE(0, arr, val)
237 nextOff <- POKE(0, arr, val)
238 genericPeekByteIndex arr 0 `shouldReturn` val
238 genericPeekByteIndex arr 0 `shouldReturn` val
test/Streamly/Test/Data/Unbox/TH.hs+1−1
@@ -28,7 +28,7 @@ testSerialization ::
28 => a
28 => a
29 -> IO ()
29 -> IO ()
30testSerialization val = do
30testSerialization val = do
31− arr <- newBytes (sizeOf (Proxy :: Proxy a))
31+ arr <- newByteArray (sizeOf (Proxy :: Proxy a))
32 pokeByteIndex 0 arr val
32 pokeByteIndex 0 arr val
33 peekByteIndex 0 arr `shouldReturn` val
33 peekByteIndex 0 arr `shouldReturn` val
34
34