on master help sign in
Create array with the new element inserted
commit889be18fc9e8cd8b0bea9042dc9e8364c005979c authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateWed 20 Apr 2022, 23:28 (4 years ago) parent3eae020
1 file changed+7−3
core/src/Streamly/Internal/Data/Ring/Foreign.hs+7−3
core/src/Streamly/Internal/Data/Ring/Foreign.hs+7−3
@@ -514,7 +514,11 @@ unsafeFoldRingNM count rh f z rb@Ring {..} =
514514
515515data Tuple4' a b c d = Tuple4' !a !b !c !d deriving Show
516516
517−-- | IMPORTANT NOTE: The ring is mutable, therefore, the result of @(m (Array
517+-- | Like slidingWindow but also provides the entire ring contents as an Array.
518+-- The array reflects the state of the ring after inserting the incoming
519+-- element.
520+--
521+-- IMPORTANT NOTE: The ring is mutable, therefore, the result of @(m (Array
518522-- a))@ action depends on when it is executed. It does not capture the sanpshot
519523-- of the ring at a particular time.
520524{-# INLINE slidingWindowWith #-}
@@ -544,7 +548,7 @@ slidingWindowWith n (Fold step1 initial1 extract1) = Fold step initial extract
544548 | i < n = do
545549 rh1 <- liftIO $ unsafeInsert rb rh a
546550 liftIO $ touchForeignPtr (ringStart rb)
547− r <- step1 st ((a, Nothing), toArray unsafeFoldRingM rb rh)
551+ r <- step1 st ((a, Nothing), toArray unsafeFoldRingM rb rh1)
548552 return $
549553 case r of
550554 Partial s -> Partial $ Tuple4' rb rh1 (i + 1) s
@@ -553,7 +557,7 @@ slidingWindowWith n (Fold step1 initial1 extract1) = Fold step initial extract
553557 old <- liftIO $ peek rh
554558 rh1 <- liftIO $ unsafeInsert rb rh a
555559 liftIO $ touchForeignPtr (ringStart rb)
556− r <- step1 st ((a, Just old), toArray unsafeFoldRingFullM rb rh)
560+ r <- step1 st ((a, Just old), toArray unsafeFoldRingFullM rb rh1)
557561 return $
558562 case r of
559563 Partial s -> Partial $ Tuple4' rb rh1 (i + 1) s