on master help sign in
Fix performance of Foldable instance of streams for GHC-9
6587585Ranjeet Kumar Ranjan
src/Streamly/Internal/BaseCompat.hs+9
@@ -14,12 +14,14 @@ module Streamly.Internal.BaseCompat
14 , fromLeft
14 , fromLeft
15 , fromRight
15 , fromRight
16 , unsafeWithForeignPtr
16 , unsafeWithForeignPtr
17+ , oneShot
17 )
18 )
18where
19where
19
20
20import Data.Coerce (Coercible, coerce)
21import Data.Coerce (Coercible, coerce)
21#if MIN_VERSION_base(4,10,0)
22#if MIN_VERSION_base(4,10,0)
22import Data.Either (fromRight, fromLeft)
23import Data.Either (fromRight, fromLeft)
24+import qualified GHC.Exts as GHCExt
23#endif
25#endif
24import GHC.ForeignPtr (ForeignPtr(..))
26import GHC.ForeignPtr (ForeignPtr(..))
25import GHC.Ptr (Ptr(..))
27import GHC.Ptr (Ptr(..))
@@ -55,3 +57,10 @@ unsafeWithForeignPtr = GHCForeignPtr.unsafeWithForeignPtr
55#else
57#else
56unsafeWithForeignPtr = withForeignPtr
58unsafeWithForeignPtr = withForeignPtr
57#endif
59#endif
60+
61+oneShot :: (a -> b) -> a -> b
62+#if MIN_VERSION_base(4,10,0)
63+oneShot = GHCExt.oneShot
64+#else
65+oneShot = id
66+#endif
src/Streamly/Internal/Data/Stream/Instances.hs+1−1
@@ -132,7 +132,7 @@ instance (Foldable m, Monad m) => Foldable (STREAM m) where { \
132 \
132 \
133 {-# INLINE foldl' #-}; \
133 {-# INLINE foldl' #-}; \
134 foldl' f z0 xs = foldr f' id xs z0 \
134 foldl' f z0 xs = foldr f' id xs z0 \
135− where { f' x k z = k $! f z x}; \
135+ where {f' x k = oneShot $ \z -> k $! f z x}; \
136 \
136 \
137 {-# INLINE length #-}; \
137 {-# INLINE length #-}; \
138 length = foldl' (\n _ -> n + 1) 0; \
138 length = foldl' (\n _ -> n + 1) 0; \
src/Streamly/Internal/Data/Stream/Serial.hs+1−1
@@ -66,7 +66,7 @@ import GHC.Exts (IsList(..), IsString(..))
66import Text.Read
66import Text.Read
67 ( Lexeme(Ident), lexP, parens, prec, readPrec, readListPrec
67 ( Lexeme(Ident), lexP, parens, prec, readPrec, readListPrec
68 , readListPrecDefault)
68 , readListPrecDefault)
69−import Streamly.Internal.BaseCompat ((#.), errorWithoutStackTrace)
69+import Streamly.Internal.BaseCompat ((#.), errorWithoutStackTrace, oneShot)
70import Streamly.Internal.Data.Stream.StreamK.Type
70import Streamly.Internal.Data.Stream.StreamK.Type
71 (IsStream(..), adapt, Stream, mkStream, foldStream)
71 (IsStream(..), adapt, Stream, mkStream, foldStream)
72import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
72import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
src/Streamly/Internal/Data/Stream/Zip.hs+1−1
@@ -53,7 +53,7 @@ import GHC.Exts (IsList(..), IsString(..))
53import Text.Read
53import Text.Read
54 ( Lexeme(Ident), lexP, parens, prec, readPrec, readListPrec
54 ( Lexeme(Ident), lexP, parens, prec, readPrec, readListPrec
55 , readListPrecDefault)
55 , readListPrecDefault)
56−import Streamly.Internal.BaseCompat ((#.), errorWithoutStackTrace)
56+import Streamly.Internal.BaseCompat ((#.), errorWithoutStackTrace, oneShot)
57import Streamly.Internal.Data.Stream.StreamK (IsStream(..), Stream)
57import Streamly.Internal.Data.Stream.StreamK (IsStream(..), Stream)
58import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
58import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
59import Streamly.Internal.Data.SVar (MonadAsync)
59import Streamly.Internal.Data.SVar (MonadAsync)