Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/streamly-benchmarks.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ description: Benchmarks are separated from the main package because we
flag fusion-plugin
description: Use fusion plugin for benchmarks and executables
manual: True
default: False
default: True

flag limit-build-mem
description: Limits memory when building the executables
Expand Down
3 changes: 3 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ packages: streamly.cabal
, benchmark/streamly-benchmarks.cabal
, bench-test-lib/bench-test-lib.cabal

-- For compiling standalone programs
-- write-ghc-environment-files: always

-- For debugging heap overflow
-- jobs: 1

Expand Down
23 changes: 17 additions & 6 deletions core/src/Streamly/Internal/Data/Stream/Eliminate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -580,17 +580,25 @@ isSubsequenceOf (Stream stepa ta) (Stream stepb tb) = go SPEC Nothing' ta tb
Skip sb' -> go SPEC (Just' x) sa sb'
Stop -> return False

-- | @stripPrefix prefix input@ strips the @prefix@ stream from the @input@
-- stream if it is a prefix of input. Returns 'Nothing' if the input does not
-- start with the given prefix, stripped input otherwise. Returns @Just nil@
-- when the prefix is the same as the input stream.
-- NOTE: Unlike 'dropPrefix', which always returns a transformed stream,
-- this function returns @Maybe@ to indicate whether the prefix matched.

-- | @stripPrefix prefix input@ strips the @prefix@ stream from the @input@ if
-- present.
--
-- If the input begins with the given prefix, returns @Just@ the remaining
-- stream. If the input does not start with the prefix, returns 'Nothing'.
--
-- It may consume both the streams partially up to the point of failure.
--
-- Space: @O(1)@
-- /Space:/ @O(1)@
--
{-# INLINE_NORMAL stripPrefix #-}
stripPrefix
:: (Monad m, Eq a)
=> Stream m a -> Stream m a -> m (Maybe (Stream m a))
=> Stream m a -- ^ Prefix to remove
-> Stream m a -- ^ Input stream
-> m (Maybe (Stream m a)) -- ^ Remaining stream if prefix matches
stripPrefix (Stream stepa ta) (Stream stepb tb) = go SPEC Nothing' ta tb

where
Expand Down Expand Up @@ -674,6 +682,9 @@ isSuffixOfUnbox :: (MonadIO m, Eq a, Unbox a) =>
isSuffixOfUnbox suffix stream =
StreamD.reverseUnbox suffix `isPrefixOf` StreamD.reverseUnbox stream

-- XXX this buffers both streams. Buffering should be equal to the size of the
-- suffix.

-- | Drops the given suffix from a stream. Returns 'Nothing' if the stream does
-- not end with the given suffix. Returns @Just nil@ when the suffix is the
-- same as the stream.
Expand Down
Loading
Loading