on master help sign in
Add INLINE to zipWith and zipWithM
commit36c22e3b5b85be35ce6228b78627a849aaa13d00 authorHarendra Kumar <harendra@composewell.com> dateTue 28 Sep 2021, 00:03 (5 years ago) parent36bbaed
2 files changed+13−5
benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs+5 src/Streamly/Internal/Data/Stream/StreamK.hs+8−5
benchmark/Streamly/Benchmark/Data/Stream/StreamK.hs+5
@@ -384,6 +384,10 @@ iterateDropWhileTrue streamLen iterStreamLen =
384384zipWith :: Monad m => Stream m Int -> m ()
385385zipWith src = drain $ S.zipWith (,) src src
386386
387+{-# INLINE zipWithM #-}
388+zipWithM :: Monad m => Stream m Int -> m ()
389+zipWithM src = drain $ S.zipWithM (curry return) src src
390+
387391{-# INLINE sortByK #-}
388392sortByK :: (a -> a -> Ordering) -> Stream m a -> Stream m a
389393sortByK f = S.concatPairsWith (S.mergeBy f) S.fromPure
@@ -745,6 +749,7 @@ o_1_space_zipping :: Int -> Benchmark
745749o_1_space_zipping streamLen =
746750 bgroup "zipping"
747751 [ benchFold "zipWith" zipWith (unfoldrM streamLen)
752+ , benchFold "zipWithM" zipWithM (unfoldrM streamLen)
748753 ]
749754
750755o_1_space_mixed :: Int -> Benchmark
src/Streamly/Internal/Data/Stream/StreamK.hs+8−5
@@ -750,10 +750,12 @@ mapMaybe f = go
750750-- | Zip two streams serially using a pure zipping function.
751751--
752752-- @since 0.1.0
753−{-# INLINABLE zipWith #-}
753+{-# INLINE zipWith #-}
754754zipWith :: (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c
755755zipWith f = go
756+
756757 where
758+
757759 go mx my = mkStream $ \st yld sng stp -> do
758760 let merge a ra =
759761 let single2 b = sng (f a b)
@@ -766,16 +768,17 @@ zipWith f = go
766768-- | Zip two streams serially using a monadic zipping function.
767769--
768770-- @since 0.1.0
769−{-# INLINABLE zipWithM #-}
771+{-# INLINE zipWithM #-}
770772zipWithM :: Monad m =>
771773 (a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c
772774zipWithM f = go
775+
773776 where
777+
774778 go mx my = mkStream $ \st yld sng stp -> do
775779 let merge a ra =
776− let runIt x = foldStream st yld sng stp x
777− single2 b = f a b >>= sng
778− yield2 b rb = f a b >>= \x -> runIt (x `cons` go ra rb)
780+ let single2 b = f a b >>= sng
781+ yield2 b rb = f a b >>= \x -> yld x (go ra rb)
779782 in foldStream (adaptState st) yield2 single2 stp my
780783 let single1 a = merge a nil
781784 yield1 = merge