on master help sign in
Fix performance of Foldable instance of streams for GHC-9

Fix warning issues

commit65875852d52a1b3d589ca8af1a35f82b1e67010f authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateFri 18 Jun 2021, 16:41 (5 years ago) parent38528ff
4 files changed+12−3
src/Streamly/Internal/BaseCompat.hs+9 src/Streamly/Internal/Data/Stream/Instances.hs+1−1 src/Streamly/Internal/Data/Stream/Serial.hs+1−1 src/Streamly/Internal/Data/Stream/Zip.hs+1−1
src/Streamly/Internal/BaseCompat.hs+9
@@ -14,12 +14,14 @@ module Streamly.Internal.BaseCompat
1414 , fromLeft
1515 , fromRight
1616 , unsafeWithForeignPtr
17+ , oneShot
1718 )
1819where
1920
2021import Data.Coerce (Coercible, coerce)
2122#if MIN_VERSION_base(4,10,0)
2223import Data.Either (fromRight, fromLeft)
24+import qualified GHC.Exts as GHCExt
2325#endif
2426import GHC.ForeignPtr (ForeignPtr(..))
2527import GHC.Ptr (Ptr(..))
@@ -55,3 +57,10 @@ unsafeWithForeignPtr = GHCForeignPtr.unsafeWithForeignPtr
5557#else
5658unsafeWithForeignPtr = withForeignPtr
5759#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 { \
132132 \
133133 {-# INLINE foldl' #-}; \
134134 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}; \
136136 \
137137 {-# INLINE length #-}; \
138138 length = foldl' (\n _ -> n + 1) 0; \
src/Streamly/Internal/Data/Stream/Serial.hs+1−1
@@ -66,7 +66,7 @@ import GHC.Exts (IsList(..), IsString(..))
6666import Text.Read
6767 ( Lexeme(Ident), lexP, parens, prec, readPrec, readListPrec
6868 , readListPrecDefault)
69−import Streamly.Internal.BaseCompat ((#.), errorWithoutStackTrace)
69+import Streamly.Internal.BaseCompat ((#.), errorWithoutStackTrace, oneShot)
7070import Streamly.Internal.Data.Stream.StreamK.Type
7171 (IsStream(..), adapt, Stream, mkStream, foldStream)
7272import 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(..))
5353import Text.Read
5454 ( Lexeme(Ident), lexP, parens, prec, readPrec, readListPrec
5555 , readListPrecDefault)
56−import Streamly.Internal.BaseCompat ((#.), errorWithoutStackTrace)
56+import Streamly.Internal.BaseCompat ((#.), errorWithoutStackTrace, oneShot)
5757import Streamly.Internal.Data.Stream.StreamK (IsStream(..), Stream)
5858import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
5959import Streamly.Internal.Data.SVar (MonadAsync)