Skip to content

Commit

Permalink
Do not reverse chunks in lazy breakEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMatten committed May 14, 2021
1 parent 01a2ec0 commit c76b9aa
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Data/Text/Lazy.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE BangPatterns, MagicHash, CPP, TypeFamilies #-}
{-# LANGUAGE BangPatterns, MagicHash, CPP, OverloadedStrings, TypeFamilies #-}
#if __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
#endif
Expand Down Expand Up @@ -1411,8 +1411,15 @@ break p t0 = break' t0
-- >>> T.breakEnd (=='0') "180cm"
-- ("180","cm")
breakEnd :: (Char -> Bool) -> Text -> (Text, Text)
breakEnd p src = let (a,b) = break p (reverse src)
in (reverse b, reverse a)
breakEnd p src = breakEnd' (reverseSpine src) where
reverseSpine = go Empty where
go res Empty = res
go res (Chunk t ts) = go (Chunk t res) ts
breakEnd' = go Empty where
go r Empty = (empty, r)
go r (Chunk t ts) = case T.breakEnd p t of
("", _) -> go (Chunk t r) ts
(l, r') -> (reverseSpine (Chunk l ts), Chunk r' r)
{-# INLINE breakEnd #-}

-- | /O(n)/ 'span', applied to a predicate @p@ and text @t@, returns
Expand Down

0 comments on commit c76b9aa

Please sign in to comment.