on master help sign in
Rename newByteArray to new
56fd008Harendra Kumar
benchmark/Streamly/Benchmark/Data/Serialize.hs+6−5
@@ -25,6 +25,7 @@ import Test.QuickCheck (Arbitrary, arbitrary)
25#endif
25#endif
26
26
27import Streamly.Internal.Data.MutByteArray hiding (encode)
27import Streamly.Internal.Data.MutByteArray hiding (encode)
28+import qualified Streamly.Internal.Data.MutByteArray as MBA
28#ifdef USE_UNBOX
29#ifdef USE_UNBOX
29import Data.Proxy (Proxy(..))
30import Data.Proxy (Proxy(..))
30#else
31#else
@@ -335,7 +336,7 @@ pokeWithSize arr val = do
335pokeTimesWithSize :: SERIALIZE_CLASS a => a -> Int -> IO ()
336pokeTimesWithSize :: SERIALIZE_CLASS a => a -> Int -> IO ()
336pokeTimesWithSize val times = do
337pokeTimesWithSize val times = do
337 let n = getSize val
338 let n = getSize val
338− arr <- newByteArray n
339+ arr <- MBA.new n
339 loopWith times pokeWithSize arr val
340 loopWith times pokeWithSize arr val
340-}
341-}
341
342
@@ -347,14 +348,14 @@ poke arr val = SERIALIZE_OP 0 arr val >> return ()
347pokeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
348pokeTimes :: SERIALIZE_CLASS a => a -> Int -> IO ()
348pokeTimes val times = do
349pokeTimes val times = do
349 let n = getSize val
350 let n = getSize val
350− arr <- newByteArray n
351+ arr <- MBA.new n
351 loopWith times poke arr val
352 loopWith times poke arr val
352
353
353{-# INLINE encode #-}
354{-# INLINE encode #-}
354encode :: SERIALIZE_CLASS a => a -> IO ()
355encode :: SERIALIZE_CLASS a => a -> IO ()
355encode val = do
356encode val = do
356 let n = getSize val
357 let n = getSize val
357− arr <- newByteArray n
358+ arr <- MBA.new n
358 SERIALIZE_OP 0 arr val >> return ()
359 SERIALIZE_OP 0 arr val >> return ()
359
360
360{-# INLINE encodeTimes #-}
361{-# INLINE encodeTimes #-}
@@ -390,7 +391,7 @@ peek (_val, n) arr = do
390{-# INLINE peekTimes #-}
391{-# INLINE peekTimes #-}
391peekTimes :: (NFData a, SERIALIZE_CLASS a) => Int -> a -> Int -> IO ()
392peekTimes :: (NFData a, SERIALIZE_CLASS a) => Int -> a -> Int -> IO ()
392peekTimes n val times = do
393peekTimes n val times = do
393− arr <- newByteArray n
394+ arr <- MBA.new n
394 _ <- SERIALIZE_OP 0 arr val
395 _ <- SERIALIZE_OP 0 arr val
395 loopWith times peek (val, n) arr
396 loopWith times peek (val, n) arr
396
397
@@ -398,7 +399,7 @@ peekTimes n val times = do
398trip :: forall a. (NFData a, SERIALIZE_CLASS a) => a -> IO ()
399trip :: forall a. (NFData a, SERIALIZE_CLASS a) => a -> IO ()
399trip val = do
400trip val = do
400 let n = getSize val
401 let n = getSize val
401− arr <- newByteArray n
402+ arr <- MBA.new n
402 _ <- SERIALIZE_OP 0 arr val
403 _ <- SERIALIZE_OP 0 arr val
403#ifdef USE_UNBOX
404#ifdef USE_UNBOX
404 (val1 :: a) <- DESERIALIZE_OP 0 arr
405 (val1 :: a) <- DESERIALIZE_OP 0 arr
core/src/Streamly/Data/MutByteArray.hs+2−2
@@ -52,8 +52,8 @@ module Streamly.Data.MutByteArray
52 , isPinned
52 , isPinned
53 , pin
53 , pin
54 , unpin
54 , unpin
55− , newByteArray
55+ , new
56− , pinnedNewByteArray
56+ , pinnedNew
57
57
58 -- * Unbox
58 -- * Unbox
59 , Unbox(..)
59 , Unbox(..)
core/src/Streamly/Internal/Data/IORef/Unboxed.hs+3−3
@@ -40,10 +40,10 @@ where
40
40
41import Control.Monad.IO.Class (MonadIO(..))
41import Control.Monad.IO.Class (MonadIO(..))
42import Data.Proxy (Proxy(..))
42import Data.Proxy (Proxy(..))
43−import Streamly.Internal.Data.MutByteArray.Type
43+import Streamly.Internal.Data.MutByteArray.Type (MutByteArray)
44− (MutByteArray(..), newByteArray)
45import Streamly.Internal.Data.Unbox (Unbox(..), sizeOf)
44import Streamly.Internal.Data.Unbox (Unbox(..), sizeOf)
46
45
46+import qualified Streamly.Internal.Data.MutByteArray.Type as MBA
47import qualified Streamly.Internal.Data.Stream.Type as D
47import qualified Streamly.Internal.Data.Stream.Type as D
48
48
49-- | An 'IORef' holds a single 'Unbox'-able value.
49-- | An 'IORef' holds a single 'Unbox'-able value.
@@ -55,7 +55,7 @@ newtype IORef a = IORef MutByteArray
55{-# INLINE newIORef #-}
55{-# INLINE newIORef #-}
56newIORef :: forall a. Unbox a => a -> IO (IORef a)
56newIORef :: forall a. Unbox a => a -> IO (IORef a)
57newIORef x = do
57newIORef x = do
58− var <- newByteArray (sizeOf (Proxy :: Proxy a))
58+ var <- MBA.new (sizeOf (Proxy :: Proxy a))
59 pokeByteIndex 0 var x
59 pokeByteIndex 0 var x
60 return $ IORef var
60 return $ IORef var
61
61
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.pinnedNewByteArray newCapMaxInBytes
747+ then Unboxed.pinnedNew newCapMaxInBytes
748− else Unboxed.newByteArray newCapMaxInBytes
748+ else Unboxed.new 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.pinnedNewByteArray newLen
2137+ then Unboxed.pinnedNew newLen
2138− else Unboxed.newByteArray newLen
2138+ else Unboxed.new 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/MutByteArray/Type.hs+13−13
@@ -24,8 +24,8 @@ module Streamly.Internal.Data.MutByteArray.Type
24 -- ** Allocation
24 -- ** Allocation
25 , nil
25 , nil
26 , newBytesAs
26 , newBytesAs
27− , newByteArray
27+ , new
28− , pinnedNewByteArray
28+ , pinnedNew
29 , pinnedNewAlignedBytes
29 , pinnedNewAlignedBytes
30
30
31 -- ** Access
31 -- ** Access
@@ -122,23 +122,23 @@ asPtrUnsafe arr f = do
122
122
123{-# NOINLINE nil #-}
123{-# NOINLINE nil #-}
124nil :: MutByteArray
124nil :: MutByteArray
125−nil = unsafePerformIO $ newByteArray 0
125+nil = unsafePerformIO $ new 0
126
126
127−{-# INLINE newByteArray #-}
127+{-# INLINE new #-}
128−newByteArray :: Int -> IO MutByteArray
128+new :: Int -> IO MutByteArray
129−newByteArray nbytes | nbytes < 0 =
129+new nbytes | nbytes < 0 =
130 errorWithoutStackTrace "newByteArray: size must be >= 0"
130 errorWithoutStackTrace "newByteArray: size must be >= 0"
131−newByteArray (I# nbytes) = IO $ \s ->
131+new (I# nbytes) = IO $ \s ->
132 case newByteArray# nbytes s of
132 case newByteArray# nbytes s of
133 (# s', mbarr# #) ->
133 (# s', mbarr# #) ->
134 let c = MutByteArray mbarr#
134 let c = MutByteArray mbarr#
135 in (# s', c #)
135 in (# s', c #)
136
136
137−{-# INLINE pinnedNewByteArray #-}
137+{-# INLINE pinnedNew #-}
138−pinnedNewByteArray :: Int -> IO MutByteArray
138+pinnedNew :: Int -> IO MutByteArray
139−pinnedNewByteArray nbytes | nbytes < 0 =
139+pinnedNew nbytes | nbytes < 0 =
140 errorWithoutStackTrace "pinnedNewByteArray: size must be >= 0"
140 errorWithoutStackTrace "pinnedNewByteArray: size must be >= 0"
141−pinnedNewByteArray (I# nbytes) = IO $ \s ->
141+pinnedNew (I# nbytes) = IO $ \s ->
142 case newPinnedByteArray# nbytes s of
142 case newPinnedByteArray# nbytes s of
143 (# s', mbarr# #) ->
143 (# s', mbarr# #) ->
144 let c = MutByteArray mbarr#
144 let c = MutByteArray mbarr#
@@ -156,8 +156,8 @@ pinnedNewAlignedBytes (I# nbytes) (I# align) = IO $ \s ->
156
156
157{-# INLINE newBytesAs #-}
157{-# INLINE newBytesAs #-}
158newBytesAs :: PinnedState -> Int -> IO MutByteArray
158newBytesAs :: PinnedState -> Int -> IO MutByteArray
159−newBytesAs Unpinned = newByteArray
159+newBytesAs Unpinned = new
160−newBytesAs Pinned = pinnedNewByteArray
160+newBytesAs Pinned = pinnedNew
161
161
162-------------------------------------------------------------------------------
162-------------------------------------------------------------------------------
163-- Copying
163-- 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.MutByteArray (MutByteArray, newByteArray)
25+import Streamly.Internal.Data.MutByteArray (MutByteArray)
26import GHC.Generics (Generic)
26import GHC.Generics (Generic)
27import Streamly.Data.MutByteArray (Serialize)
27import Streamly.Data.MutByteArray (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 <- newByteArray arrSize
172+ arr <- Serialize.new 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+3−2
@@ -28,6 +28,7 @@ import GHC.Generics (Generic, Rep(..))
28import GHC.Real (Ratio(..))
28import GHC.Real (Ratio(..))
29
29
30import Streamly.Internal.Data.MutByteArray
30import Streamly.Internal.Data.MutByteArray
31+import qualified Streamly.Internal.Data.MutByteArray as MBA
31
32
32import Test.Hspec as H
33import Test.Hspec as H
33
34
@@ -198,7 +199,7 @@ testSerialization val = do
198#else
199#else
199 (sizeOf (Proxy :: Proxy a))
200 (sizeOf (Proxy :: Proxy a))
200#endif
201#endif
201− arr <- newByteArray len
202+ arr <- MBA.new len
202 nextOff <- POKE(0, arr, val)
203 nextOff <- POKE(0, arr, val)
203 (nextOff1, val1) <- PEEK(0, arr, len)
204 (nextOff1, val1) <- PEEK(0, arr, len)
204 val1 `shouldBe` val
205 val1 `shouldBe` val
@@ -232,7 +233,7 @@ testGenericConsistency val = do
232 len `shouldBe` genericSizeOf (Proxy :: Proxy a)
233 len `shouldBe` genericSizeOf (Proxy :: Proxy a)
233
234
234 -- Test the serialization and deserialization
235 -- Test the serialization and deserialization
235− arr <- newByteArray (sizeOf (Proxy :: Proxy a))
236+ arr <- MBA.new (sizeOf (Proxy :: Proxy a))
236
237
237 nextOff <- POKE(0, arr, val)
238 nextOff <- POKE(0, arr, val)
238 genericPeekByteIndex arr 0 `shouldReturn` val
239 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
16
16
17import Data.Proxy (Proxy(..))
17import Data.Proxy (Proxy(..))
18import Streamly.Internal.Data.MutByteArray
18import Streamly.Internal.Data.MutByteArray
19+import qualified Streamly.Internal.Data.MutByteArray as MBA
19
20
20import Test.Hspec as H
21import Test.Hspec as H
21
22
@@ -28,7 +29,7 @@ testSerialization ::
28 => a
29 => a
29 -> IO ()
30 -> IO ()
30testSerialization val = do
31testSerialization val = do
31− arr <- newByteArray (sizeOf (Proxy :: Proxy a))
32+ arr <- MBA.new (sizeOf (Proxy :: Proxy a))
32 pokeByteIndex 0 arr val
33 pokeByteIndex 0 arr val
33 peekByteIndex 0 arr `shouldReturn` val
34 peekByteIndex 0 arr `shouldReturn` val
34
35