on master help sign in
Mv bemchmarks & change INLINABLE to INLINE - lastN
5faf292adithyaov
benchmark/Linear.hs+3−3
@@ -201,9 +201,6 @@ main =
201 -- this is too low and causes all benchmarks reported in ns
201 -- this is too low and causes all benchmarks reported in ns
202 -- , benchIOSink "head" Ops.head
202 -- , benchIOSink "head" Ops.head
203 , benchIOSink "last" Ops.last
203 , benchIOSink "last" Ops.last
204− , benchIOSink "lastN.1" (S.fold (IA.lastN 1))
205− , benchIOSink "lastN.10" (S.fold (IA.lastN 10))
206− , benchIOSink "lastN.Max" (S.fold (IA.lastN Ops.maxValue))
207 -- , benchIOSink "lookup" Ops.lookup
204 -- , benchIOSink "lookup" Ops.lookup
208 , benchIOSink "find" Ops.find
205 , benchIOSink "find" Ops.find
209 , benchIOSink "findIndex" Ops.findIndex
206 , benchIOSink "findIndex" Ops.findIndex
@@ -238,6 +235,9 @@ main =
238 , benchIOSink "drainWhileFalse" (S.fold (IFL.drainWhile $ (>=) Ops.maxValue))
235 , benchIOSink "drainWhileFalse" (S.fold (IFL.drainWhile $ (>=) Ops.maxValue))
239 , benchIOSink "sink" (S.fold $ Sink.toFold Sink.drain)
236 , benchIOSink "sink" (S.fold $ Sink.toFold Sink.drain)
240 , benchIOSink "last" (S.fold FL.last)
237 , benchIOSink "last" (S.fold FL.last)
238+ , benchIOSink "lastN.1" (S.fold (IA.lastN 1))
239+ , benchIOSink "lastN.10" (S.fold (IA.lastN 10))
240+ , benchIOSink "lastN.Max" (S.fold (IA.lastN Ops.maxValue))
241 , benchIOSink "length" (S.fold FL.length)
241 , benchIOSink "length" (S.fold FL.length)
242 , benchIOSink "sum" (S.fold FL.sum)
242 , benchIOSink "sum" (S.fold FL.sum)
243 , benchIOSink "product" (S.fold FL.product)
243 , benchIOSink "product" (S.fold FL.product)
src/Streamly/Internal/Data/Stream/StreamD.hs+3−5
@@ -306,8 +306,6 @@ module Streamly.Internal.Data.Stream.StreamD
306 , applyParallel
306 , applyParallel
307 , foldParallel
307 , foldParallel
308
308
309− -- XXX Move this later
310− -- XXX Exported from Array again
311 , lastN
309 , lastN
312 )
310 )
313where
311where
@@ -4019,16 +4017,16 @@ tapAsync f (Stream step1 state1) = Stream step TapInit
4019 Skip s -> Skip (TapDone s)
4017 Skip s -> Skip (TapDone s)
4020 Stop -> Stop
4018 Stop -> Stop
4021
4019
4022−-- XXX Is there room for improvement?
4020+-- XXX Exported from Array again as this fold is specific to Array
4023-- | Take last 'n' elements from the stream and discard the rest.
4021-- | Take last 'n' elements from the stream and discard the rest.
4024−{-# INLINABLE lastN #-}
4022+{-# INLINE lastN #-}
4025lastN :: (Storable a, MonadIO m) => Int -> Fold m a (Array a)
4023lastN :: (Storable a, MonadIO m) => Int -> Fold m a (Array a)
4026lastN n = Fold step initial done
4024lastN n = Fold step initial done
4027 where
4025 where
4028 step (Tuple3' rb rh i) a = do
4026 step (Tuple3' rb rh i) a = do
4029 rh1 <- liftIO $ RB.unsafeInsert rb rh a
4027 rh1 <- liftIO $ RB.unsafeInsert rb rh a
4030 return $ Tuple3' rb rh1 (i + 1)
4028 return $ Tuple3' rb rh1 (i + 1)
4031− initial = fmap (\(a, b) -> Tuple3' a b 0) $ liftIO $ RB.new n
4029+ initial = fmap (\(a, b) -> Tuple3' a b (0 :: Int)) $ liftIO $ RB.new n
4032 done (Tuple3' rb rh i) = do
4030 done (Tuple3' rb rh i) = do
4033 arr <- liftIO $ A.newArray n
4031 arr <- liftIO $ A.newArray n
4034 foldFunc i rh snoc' arr rb
4032 foldFunc i rh snoc' arr rb