on master help sign in
Rename write* to create* in Array module
8e8159fHarendra Kumar
core/src/DocTestFileSystemHandle.hs+1−1
@@ -8,7 +8,7 @@
8
8
9For APIs that have not been released yet.
9For APIs that have not been released yet.
10
10
11−>>> import qualified Streamly.Internal.Data.Array as Array (writeNUnsafe)
11+>>> import qualified Streamly.Internal.Data.Array as Array (unsafeCreateOf)
12>>> import qualified Streamly.Internal.Data.Unfold as Unfold (first)
12>>> import qualified Streamly.Internal.Data.Unfold as Unfold (first)
13>>> import qualified Streamly.Internal.FileSystem.Handle as Handle
13>>> import qualified Streamly.Internal.FileSystem.Handle as Handle
14>>> import qualified Streamly.Internal.System.IO as IO (defaultChunkSize)
14>>> import qualified Streamly.Internal.System.IO as IO (defaultChunkSize)
core/src/Streamly/Data/Array.hs+28−24
@@ -31,42 +31,42 @@ module Streamly.Data.Array
31 -- * The Array Type
31 -- * The Array Type
32 Array
32 Array
33
33
34+ -- * Pinning & Unpinning
35+ -- | Arrays are created unpinned by default unless pinned versions of
36+ -- creation APIs are used. Look for APIs with @pinned@ prefix in
37+ -- "Streamly.Internal.Data.Array" for some unreleased pinned creation APIs.
38+ -- If an array is to be sent to the OS without any further modification
39+ -- then it should be created pinned in the first place instead of pinning
40+ -- it later. Pinning an unpinned array has a copy overhead. OS interfacing
41+ -- APIs create a pinned array directly or convert an unpinned array to
42+ -- pinned array before sending it to the OS.
43+ , pin
44+ , unpin
45+ , isPinned
46+
34 -- * Construction
47 -- * Construction
35 -- | When performance matters, the fastest way to generate an array is
48 -- | When performance matters, the fastest way to generate an array is
36− -- 'writeN'. 'IsList' and 'IsString' instances can be
49+ -- 'createOf'. 'IsList' and 'IsString' instances can be
37 -- used to conveniently construct arrays from literal values.
50 -- used to conveniently construct arrays from literal values.
38 -- 'OverloadedLists' extension or 'fromList' can be used to construct an
51 -- 'OverloadedLists' extension or 'fromList' can be used to construct an
39 -- array from a list literal. Similarly, 'OverloadedStrings' extension or
52 -- array from a list literal. Similarly, 'OverloadedStrings' extension or
40 -- 'fromList' can be used to construct an array from a string literal.
53 -- 'fromList' can be used to construct an array from a string literal.
41
54
55+ -- ** From Stream
56+ , createOf
57+ , create
58+ , writeLastN -- drop old (ring buffer)
59+
42− -- Pure List APIs
60+ -- ** From List
43 , fromListN
61 , fromListN
44 , fromList
62 , fromList
45
63
46− -- Monadic APIs
64+ -- * To List
47− , writeN -- drop new
48− , write -- full buffer
49− , writeLastN -- drop old (ring buffer)
50−
51− -- * Conversion
52 -- 'GHC.Exts.toList' from "GHC.Exts" can be used to convert an array to a
65 -- 'GHC.Exts.toList' from "GHC.Exts" can be used to convert an array to a
53 -- list.
66 -- list.
54 , toList
67 , toList
55
68
56− -- * Pinning & Unpinning
69+ -- * To Stream
57− -- | Arrays are created unpinned by default unless pinned versions of
58− -- creation APIs are used. Look for APIs with @pinned@ prefix in
59− -- "Streamly.Internal.Data.Array" for some unreleased pinned creation APIs.
60− -- If an array is to be sent to the OS without any further modification
61− -- then it should be created pinned in the first place instead of pinning
62− -- it later. Pinning an unpinned array has a copy overhead. OS interfacing
63− -- APIs create a pinned array directly or convert an unpinned array to
64− -- pinned array before sending it to the OS.
65− , pin
66− , unpin
67− , isPinned
68−
69− -- * Streams
70 , read
70 , read
71 , readRev
71 , readRev
72
72
@@ -90,6 +90,10 @@ module Streamly.Data.Array
90 -- * Re-exports
90 -- * Re-exports
91 , Unbox (..)
91 , Unbox (..)
92 , Serialize(..)
92 , Serialize(..)
93+
94+ -- * Deprecated
95+ , writeN -- drop new
96+ , write -- full buffer
93 )
97 )
94where
98where
95
99
@@ -122,7 +126,7 @@ import Prelude hiding (read, length)
122--
126--
123-- Convert array to stream, transform, and fold back to array:
127-- Convert array to stream, transform, and fold back to array:
124--
128--
125−-- >>> amap f arr = Array.read arr & fmap f & Stream.fold Array.write
129+-- >>> amap f arr = Array.read arr & fmap f & Stream.fold Array.create
126-- >>> amap (+1) (Array.fromList [1,2,3::Int])
130-- >>> amap (+1) (Array.fromList [1,2,3::Int])
127-- fromList [2,3,4]
131-- fromList [2,3,4]
128--
132--
@@ -154,7 +158,7 @@ import Prelude hiding (read, length)
154--
158--
155-- >>> pure = Stream.fromList [1,2,3] :: Stream Identity Int
159-- >>> pure = Stream.fromList [1,2,3] :: Stream Identity Int
156-- >>> generally = Stream.morphInner (return . runIdentity)
160-- >>> generally = Stream.morphInner (return . runIdentity)
157−-- >>> Stream.fold Array.write (generally pure :: Stream IO Int)
161+-- >>> Stream.fold Array.create (generally pure :: Stream IO Int)
158-- fromList [1,2,3]
162-- fromList [1,2,3]
159--
163--
160-- == Programming Tips
164-- == Programming Tips
core/src/Streamly/Internal/Data/Array.hs+3−1
@@ -205,6 +205,8 @@ last = getIndexRev 0
205-- Folds with Array as the container
205-- Folds with Array as the container
206-------------------------------------------------------------------------------
206-------------------------------------------------------------------------------
207
207
208+-- XXX We should generate this from Ring.
209+
208-- | @writeLastN n@ folds a maximum of @n@ elements from the end of the input
210-- | @writeLastN n@ folds a maximum of @n@ elements from the end of the input
209-- stream to an 'Array'.
211-- stream to an 'Array'.
210--
212--
@@ -447,7 +449,7 @@ runPipe f arr = P.runPipe (toArrayMinChunk (length arr)) $ f (read arr)
447streamTransform :: forall m a b. (MonadIO m, Unbox a, Unbox b)
449streamTransform :: forall m a b. (MonadIO m, Unbox a, Unbox b)
448 => (Stream m a -> Stream m b) -> Array a -> m (Array b)
450 => (Stream m a -> Stream m b) -> Array a -> m (Array b)
449streamTransform f arr =
451streamTransform f arr =
450− Stream.fold (writeWith (length arr)) $ f (read arr)
452+ Stream.fold (createWith (length arr)) $ f (read arr)
451
453
452-------------------------------------------------------------------------------
454-------------------------------------------------------------------------------
453-- Casts
455-- Casts
core/src/Streamly/Internal/Data/Array/Type.hs+75−28
@@ -45,15 +45,13 @@ module Streamly.Internal.Data.Array.Type
45
45
46 -- *** Stream Folds
46 -- *** Stream Folds
47 , unsafeMakePure
47 , unsafeMakePure
48− , writeWith
48+ , createOf
49− , writeN
49+ , pinnedCreateOf
50− , pinnedWriteN
50+ , unsafeCreateOf
51− , writeNUnsafe
51+ , unsafePinnedCreateOf
52− , pinnedWriteNUnsafe
52+ , create
53− -- , MA.ArrayUnsafe (..)
53+ , pinnedCreate
54− , pinnedWriteNAligned
54+ , createWith
55− , write
56− , pinnedWrite
57
55
58 -- *** From containers
56 -- *** From containers
59 , fromListN
57 , fromListN
@@ -75,8 +73,8 @@ module Streamly.Internal.Data.Array.Type
75 -- ** Reading
73 -- ** Reading
76
74
77 -- *** Indexing
75 -- *** Indexing
78− , unsafeIndexIO -- XXX rename to getIndexUnsafeIO
76+ , unsafeIndexIO -- XXX unsafeGetIndexIO
79− , getIndexUnsafe
77+ , getIndexUnsafe -- XXX unsafeGetIndex
80
78
81 -- *** To Streams
79 -- *** To Streams
82 , read
80 , read
@@ -143,6 +141,14 @@ module Streamly.Internal.Data.Array.Type
143 , toStream
141 , toStream
144 , toStreamRev
142 , toStreamRev
145 , nil
143 , nil
144+ , writeWith
145+ , writeN
146+ , pinnedWriteN
147+ , writeNUnsafe
148+ , pinnedWriteNUnsafe
149+ , pinnedWriteNAligned
150+ , write
151+ , pinnedWrite
146 )
152 )
147where
153where
148
154
@@ -745,17 +751,28 @@ toList s = build (\c n -> toListFB c n s)
745-- Folds
751-- Folds
746-------------------------------------------------------------------------------
752-------------------------------------------------------------------------------
747
753
748−-- | @writeN n@ folds a maximum of @n@ elements from the input stream to an
754+-- | @createOf n@ folds a maximum of @n@ elements from the input stream to an
749-- 'Array'.
755-- 'Array'.
750--
756--
751−{-# INLINE_NORMAL writeN #-}
757+{-# INLINE_NORMAL createOf #-}
758+createOf :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
759+createOf = fmap unsafeFreeze . MA.createOf
760+
761+-- XXX Deprecate in major
762+-- {-# DEPRECATED writeN "Please use createOf instead." #-}
763+{-# INLINE writeN #-}
752writeN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
764writeN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
753−writeN = fmap unsafeFreeze . MA.writeN
765+writeN = createOf
754
766
755−-- | Like 'fromListN' but creates a pinned array.
767+-- | Like 'createOf' but creates a pinned array.
768+{-# INLINE_NORMAL pinnedCreateOf #-}
769+pinnedCreateOf :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
770+pinnedCreateOf = fmap unsafeFreeze . MA.pinnedCreateOf
771+
772+{-# DEPRECATED pinnedWriteN "Please use pinnedCreateOf instead." #-}
756−{-# INLINE_NORMAL pinnedWriteN #-}
773+{-# INLINE pinnedWriteN #-}
757pinnedWriteN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
774pinnedWriteN :: forall m a. (MonadIO m, Unbox a) => Int -> Fold m a (Array a)
758−pinnedWriteN = fmap unsafeFreeze . MA.pinnedCreateOf
775+pinnedWriteN = pinnedCreateOf
759
776
760-- | @pinnedWriteNAligned alignment n@ folds a maximum of @n@ elements from the input
777-- | @pinnedWriteNAligned alignment n@ folds a maximum of @n@ elements from the input
761-- stream to an 'Array' aligned to the given size.
778-- stream to an 'Array' aligned to the given size.
@@ -763,44 +780,74 @@ pinnedWriteN = fmap unsafeFreeze . MA.pinnedCreateOf
763-- /Pre-release/
780-- /Pre-release/
764--
781--
765{-# INLINE_NORMAL pinnedWriteNAligned #-}
782{-# INLINE_NORMAL pinnedWriteNAligned #-}
783+{-# DEPRECATED pinnedWriteNAligned "To be removed." #-}
766pinnedWriteNAligned :: forall m a. (MonadIO m, Unbox a)
784pinnedWriteNAligned :: forall m a. (MonadIO m, Unbox a)
767 => Int -> Int -> Fold m a (Array a)
785 => Int -> Int -> Fold m a (Array a)
768pinnedWriteNAligned alignSize = fmap unsafeFreeze . MA.pinnedWriteNAligned alignSize
786pinnedWriteNAligned alignSize = fmap unsafeFreeze . MA.pinnedWriteNAligned alignSize
769
787
770−-- | Like 'writeN' but does not check the array bounds when writing. The fold
788+-- | Like 'createOf' but does not check the array bounds when writing. The fold
771-- driver must not call the step function more than 'n' times otherwise it will
789-- driver must not call the step function more than 'n' times otherwise it will
772-- corrupt the memory and crash. This function exists mainly because any
790-- corrupt the memory and crash. This function exists mainly because any
773-- conditional in the step function blocks fusion causing 10x performance
791-- conditional in the step function blocks fusion causing 10x performance
774-- slowdown.
792-- slowdown.
775--
793--
794+{-# INLINE_NORMAL unsafeCreateOf #-}
795+unsafeCreateOf :: forall m a. (MonadIO m, Unbox a)
796+ => Int -> Fold m a (Array a)
797+unsafeCreateOf n = unsafeFreeze <$> MA.unsafeCreateOf n
798+
799+{-# DEPRECATED writeNUnsafe "Please use unsafeCreateOf instead." #-}
776−{-# INLINE_NORMAL writeNUnsafe #-}
800+{-# INLINE writeNUnsafe #-}
777writeNUnsafe :: forall m a. (MonadIO m, Unbox a)
801writeNUnsafe :: forall m a. (MonadIO m, Unbox a)
778 => Int -> Fold m a (Array a)
802 => Int -> Fold m a (Array a)
779−writeNUnsafe n = unsafeFreeze <$> MA.unsafeCreateOf n
803+writeNUnsafe = unsafeCreateOf
780
804
805+{-# INLINE_NORMAL unsafePinnedCreateOf #-}
806+unsafePinnedCreateOf :: forall m a. (MonadIO m, Unbox a)
807+ => Int -> Fold m a (Array a)
808+unsafePinnedCreateOf n = unsafeFreeze <$> MA.unsafePinnedCreateOf n
809+
810+{-# DEPRECATED pinnedWriteNUnsafe "Please use unsafePinnedCreateOf instead." #-}
781−{-# INLINE_NORMAL pinnedWriteNUnsafe #-}
811+{-# INLINE pinnedWriteNUnsafe #-}
782pinnedWriteNUnsafe :: forall m a. (MonadIO m, Unbox a)
812pinnedWriteNUnsafe :: forall m a. (MonadIO m, Unbox a)
783 => Int -> Fold m a (Array a)
813 => Int -> Fold m a (Array a)
784−pinnedWriteNUnsafe n = unsafeFreeze <$> MA.unsafePinnedCreateOf n
814+pinnedWriteNUnsafe = unsafePinnedCreateOf
815+
816+{-# INLINE_NORMAL createWith #-}
817+createWith :: forall m a. (MonadIO m, Unbox a)
818+ => Int -> Fold m a (Array a)
819+-- createWith n = FL.rmapM spliceArrays $ toArraysOf n
820+createWith elemCount = unsafeFreeze <$> MA.createWith elemCount
785
821
822+{-# DEPRECATED writeWith "Please use createWith instead." #-}
786−{-# INLINE_NORMAL writeWith #-}
823+{-# INLINE writeWith #-}
787writeWith :: forall m a. (MonadIO m, Unbox a)
824writeWith :: forall m a. (MonadIO m, Unbox a)
788 => Int -> Fold m a (Array a)
825 => Int -> Fold m a (Array a)
789−-- writeWith n = FL.rmapM spliceArrays $ toArraysOf n
790−writeWith elemCount = unsafeFreeze <$> MA.createWith elemCount
826+writeWith = createWith
791
827
792-- | Fold the whole input to a single array.
828-- | Fold the whole input to a single array.
793--
829--
794-- /Caution! Do not use this on infinite streams./
830-- /Caution! Do not use this on infinite streams./
795--
831--
832+{-# INLINE create #-}
833+create :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
834+create = fmap unsafeFreeze MA.create
835+
836+-- XXX Deprecate in major
837+-- {-# DEPRECATED write "Please use create instead." #-}
796{-# INLINE write #-}
838{-# INLINE write #-}
797write :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
839write :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
840+write = create
841+
842+-- | Like 'create' but creates a pinned array.
843+{-# INLINE pinnedCreate #-}
844+pinnedCreate :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
798−write = fmap unsafeFreeze MA.write
845+pinnedCreate = fmap unsafeFreeze MA.pinnedCreate
799
846
800−-- | Like 'write' but creates a pinned array.
847+{-# DEPRECATED pinnedWrite "Please use pinnedCreate instead." #-}
801{-# INLINE pinnedWrite #-}
848{-# INLINE pinnedWrite #-}
802pinnedWrite :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
849pinnedWrite :: forall m a. (MonadIO m, Unbox a) => Fold m a (Array a)
803−pinnedWrite = fmap unsafeFreeze MA.pinnedCreate
850+pinnedWrite = pinnedCreate
804
851
805-- | Fold "step" has a dependency on "initial", and each step is dependent on
852-- | Fold "step" has a dependency on "initial", and each step is dependent on
806-- the previous invocation of step due to state passing, finally extract
853-- the previous invocation of step due to state passing, finally extract
core/src/Streamly/Internal/FileSystem/File.hs+2−2
@@ -103,7 +103,7 @@ import qualified Control.Monad.Catch as MC
103import qualified System.IO as SIO
103import qualified System.IO as SIO
104
104
105import Streamly.Data.Fold (groupsOf, drain)
105import Streamly.Data.Fold (groupsOf, drain)
106−import Streamly.Internal.Data.Array.Type (Array(..), pinnedWriteNUnsafe)
106+import Streamly.Internal.Data.Array.Type (Array(..))
107import Streamly.Internal.Data.Fold.Type (Fold(..))
107import Streamly.Internal.Data.Fold.Type (Fold(..))
108import Streamly.Data.Stream (Stream)
108import Streamly.Data.Stream (Stream)
109import Streamly.Internal.Data.Unfold.Type (Unfold(..))
109import Streamly.Internal.Data.Unfold.Type (Unfold(..))
@@ -462,7 +462,7 @@ writeChunks path = Fold step initial extract final
462writeWith :: (MonadIO m, MonadCatch m)
462writeWith :: (MonadIO m, MonadCatch m)
463 => Int -> FilePath -> Fold m Word8 ()
463 => Int -> FilePath -> Fold m Word8 ()
464writeWith n path =
464writeWith n path =
465− groupsOf n (pinnedWriteNUnsafe n) (writeChunks path)
465+ groupsOf n (A.unsafePinnedCreateOf n) (writeChunks path)
466
466
467{-# DEPRECATED writeWithBufferOf "Please use 'writeWith' instead" #-}
467{-# DEPRECATED writeWithBufferOf "Please use 'writeWith' instead" #-}
468{-# INLINE writeWithBufferOf #-}
468{-# INLINE writeWithBufferOf #-}
core/src/Streamly/Internal/FileSystem/Handle.hs+10−10
@@ -40,8 +40,8 @@ module Streamly.Internal.FileSystem.Handle
40
40
41 -- * Streams
41 -- * Streams
42 , read
42 , read
43− , readWith
43+ , readWith -- readConcatChunksOf
44− , readChunksWith
44+ , readChunksWith -- readChunksOf
45 , readChunks
45 , readChunks
46
46
47 -- * Unfolds
47 -- * Unfolds
@@ -59,10 +59,10 @@ module Streamly.Internal.FileSystem.Handle
59 -- , writeUtf8ByLines
59 -- , writeUtf8ByLines
60 -- , writeByFrames
60 -- , writeByFrames
61 -- , writeLines
61 -- , writeLines
62− , writeWith
62+ , writeWith -- writeChunksOf
63 , writeChunks
63 , writeChunks
64− , writeChunksWith
64+ , writeChunksWith -- writeCompactChunksOf
65− , writeMaybesWith
65+ , writeMaybesWith -- writeCompactJustsOf
66
66
67 -- * Refolds
67 -- * Refolds
68 , writer
68 , writer
@@ -131,7 +131,7 @@ import Streamly.Internal.Data.Fold (Fold)
131import Streamly.Internal.Data.Refold.Type (Refold(..))
131import Streamly.Internal.Data.Refold.Type (Refold(..))
132import Streamly.Internal.Data.Unfold.Type (Unfold(..))
132import Streamly.Internal.Data.Unfold.Type (Unfold(..))
133import Streamly.Internal.Data.Array.Type
133import Streamly.Internal.Data.Array.Type
134− (Array(..), pinnedWriteNUnsafe, unsafeFreezeWithShrink, byteLength)
134+ (Array(..), unsafeFreezeWithShrink, byteLength)
135import Streamly.Internal.Data.Stream.Type (Stream)
135import Streamly.Internal.Data.Stream.Type (Stream)
136-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
136-- import Streamly.String (encodeUtf8, decodeUtf8, foldLines)
137import Streamly.Internal.System.IO (defaultChunkSize)
137import Streamly.Internal.System.IO (defaultChunkSize)
@@ -489,11 +489,11 @@ writeChunksWithBufferOf = writeChunksWith
489-- Bytes in the input stream are collected into a buffer until we have a chunk
489-- Bytes in the input stream are collected into a buffer until we have a chunk
490-- of @reqSize@ and then written to the IO device.
490-- of @reqSize@ and then written to the IO device.
491--
491--
492−-- >>> writeWith n h = Fold.groupsOf n (Array.writeNUnsafe n) (Handle.writeChunks h)
492+-- >>> writeWith n h = Fold.groupsOf n (Array.unsafeCreateOf n) (Handle.writeChunks h)
493--
493--
494{-# INLINE writeWith #-}
494{-# INLINE writeWith #-}
495writeWith :: MonadIO m => Int -> Handle -> Fold m Word8 ()
495writeWith :: MonadIO m => Int -> Handle -> Fold m Word8 ()
496−writeWith n h = FL.groupsOf n (pinnedWriteNUnsafe n) (writeChunks h)
496+writeWith n h = FL.groupsOf n (A.unsafePinnedCreateOf n) (writeChunks h)
497
497
498-- | Same as 'writeWith'
498-- | Same as 'writeWith'
499--
499--
@@ -511,7 +511,7 @@ writeWithBufferOf = writeWith
511writeMaybesWith :: (MonadIO m )
511writeMaybesWith :: (MonadIO m )
512 => Int -> Handle -> Fold m (Maybe Word8) ()
512 => Int -> Handle -> Fold m (Maybe Word8) ()
513writeMaybesWith n h =
513writeMaybesWith n h =
514− let writeNJusts = FL.lmap fromJust $ A.pinnedWriteN n
514+ let writeNJusts = FL.lmap fromJust $ A.pinnedCreateOf n
515 writeOnNothing = FL.takeEndBy_ isNothing writeNJusts
515 writeOnNothing = FL.takeEndBy_ isNothing writeNJusts
516 in FL.many writeOnNothing (writeChunks h)
516 in FL.many writeOnNothing (writeChunks h)
517
517
@@ -521,7 +521,7 @@ writeMaybesWith n h =
521{-# INLINE writerWith #-}
521{-# INLINE writerWith #-}
522writerWith :: MonadIO m => Int -> Refold m Handle Word8 ()
522writerWith :: MonadIO m => Int -> Refold m Handle Word8 ()
523writerWith n =
523writerWith n =
524− FL.refoldMany (FL.take n $ pinnedWriteNUnsafe n) chunkWriter
524+ FL.refoldMany (FL.take n $ A.unsafePinnedCreateOf n) chunkWriter
525
525
526-- | Write a byte stream to a file handle. Accumulates the input in chunks of
526-- | Write a byte stream to a file handle. Accumulates the input in chunks of
527-- up to 'Streamly.Internal.Data.Array.Type.defaultChunkSize' before writing
527-- up to 'Streamly.Internal.Data.Array.Type.defaultChunkSize' before writing
src/Streamly/Internal/Network/Inet/TCP.hs+3−3
@@ -116,7 +116,6 @@ import Prelude hiding (read)
116import Streamly.Internal.Control.Concurrent (MonadAsync)
116import Streamly.Internal.Control.Concurrent (MonadAsync)
117import Streamly.Internal.Control.ForkLifted (fork)
117import Streamly.Internal.Control.ForkLifted (fork)
118import Streamly.Data.Array (Array)
118import Streamly.Data.Array (Array)
119−import Streamly.Internal.Data.Array (pinnedWriteNUnsafe)
120import Streamly.Internal.Data.Fold ( Fold(..) )
119import Streamly.Internal.Data.Fold ( Fold(..) )
121import Streamly.Data.Stream (Stream)
120import Streamly.Data.Stream (Stream)
122import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
121import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
@@ -132,7 +131,8 @@ import qualified Streamly.Data.Array as A
132import qualified Streamly.Data.Fold as FL
131import qualified Streamly.Data.Fold as FL
133import qualified Streamly.Data.Stream as S
132import qualified Streamly.Data.Stream as S
134import qualified Streamly.Data.Unfold as UF
133import qualified Streamly.Data.Unfold as UF
135−import qualified Streamly.Internal.Data.Array as A (pinnedChunksOf)
134+import qualified Streamly.Internal.Data.Array as A
135+ (pinnedChunksOf, unsafePinnedCreateOf)
136import qualified Streamly.Internal.Data.Unfold as UF (bracketIO)
136import qualified Streamly.Internal.Data.Unfold as UF (bracketIO)
137import qualified Streamly.Internal.Data.Fold as FL (Step(..), reduce)
137import qualified Streamly.Internal.Data.Fold as FL (Step(..), reduce)
138
138
@@ -435,7 +435,7 @@ writeWithBufferOf
435 -> PortNumber
435 -> PortNumber
436 -> Fold m Word8 ()
436 -> Fold m Word8 ()
437writeWithBufferOf n addr port =
437writeWithBufferOf n addr port =
438− FL.groupsOf n (pinnedWriteNUnsafe n) (writeChunks addr port)
438+ FL.groupsOf n (A.unsafePinnedCreateOf n) (writeChunks addr port)
439
439
440-- | Write a stream to the supplied IPv4 host address and port number.
440-- | Write a stream to the supplied IPv4 host address and port number.
441--
441--
src/Streamly/Internal/Network/Socket.hs+3−3
@@ -99,7 +99,7 @@ import qualified Streamly.Data.Stream as S
99import qualified Streamly.Data.Unfold as UF
99import qualified Streamly.Data.Unfold as UF
100import qualified Streamly.Internal.Data.Array as A
100import qualified Streamly.Internal.Data.Array as A
101 ( unsafeFreeze, unsafePinnedAsPtr, byteLength, pinnedChunksOf,
101 ( unsafeFreeze, unsafePinnedAsPtr, byteLength, pinnedChunksOf,
102− pinnedWriteN, pinnedWriteNUnsafe, lCompactGE )
102+ pinnedCreateOf, unsafePinnedCreateOf, lCompactGE )
103import qualified Streamly.Internal.Data.MutArray as MArray
103import qualified Streamly.Internal.Data.MutArray as MArray
104 (MutArray(..), unsafePinnedAsPtr, pinnedEmptyOf)
104 (MutArray(..), unsafePinnedAsPtr, pinnedEmptyOf)
105import qualified Streamly.Internal.Data.Stream as S (fromStreamK, Stream(..), Step(..))
105import qualified Streamly.Internal.Data.Stream as S (fromStreamK, Stream(..), Step(..))
@@ -505,7 +505,7 @@ putBytesWith n h m = putChunks h $ A.pinnedChunksOf n m
505--
505--
506{-# INLINE writeWith #-}
506{-# INLINE writeWith #-}
507writeWith :: MonadIO m => Int -> Socket -> Fold m Word8 ()
507writeWith :: MonadIO m => Int -> Socket -> Fold m Word8 ()
508−writeWith n h = FL.groupsOf n (A.pinnedWriteNUnsafe n) (writeChunks h)
508+writeWith n h = FL.groupsOf n (A.unsafePinnedCreateOf n) (writeChunks h)
509
509
510-- | Same as 'writeWith'
510-- | Same as 'writeWith'
511--
511--
@@ -523,7 +523,7 @@ writeWithBufferOf = writeWith
523writeMaybesWith :: (MonadIO m )
523writeMaybesWith :: (MonadIO m )
524 => Int -> Socket -> Fold m (Maybe Word8) ()
524 => Int -> Socket -> Fold m (Maybe Word8) ()
525writeMaybesWith n h =
525writeMaybesWith n h =
526− let writeNJusts = FL.lmap fromJust $ A.pinnedWriteN n
526+ let writeNJusts = FL.lmap fromJust $ A.pinnedCreateOf n
527 writeOnNothing = FL.takeEndBy_ isNothing writeNJusts
527 writeOnNothing = FL.takeEndBy_ isNothing writeNJusts
528 in FL.many writeOnNothing (writeChunks h)
528 in FL.many writeOnNothing (writeChunks h)
529
529
test/Streamly/Test/Data/Array.hs+1−1
@@ -229,7 +229,7 @@ main =
229 prop "read . write === id" testFoldUnfold
229 prop "read . write === id" testFoldUnfold
230 prop "fromList" testFromList
230 prop "fromList" testFromList
231 prop "foldMany with writeNUnsafe concats to original"
231 prop "foldMany with writeNUnsafe concats to original"
232− (foldManyWith (\n -> Fold.take n (A.writeNUnsafe n)))
232+ (foldManyWith (\n -> Fold.take n (A.unsafeCreateOf n)))
233 describe "unsafeSlice" $ do
233 describe "unsafeSlice" $ do
234 it "partial" $ unsafeSlice 2 4 [1..10]
234 it "partial" $ unsafeSlice 2 4 [1..10]
235 it "none" $ unsafeSlice 10 0 [1..10]
235 it "none" $ unsafeSlice 10 0 [1..10]