Skip to content

Commit c76b9aa

Browse files
committed
Do not reverse chunks in lazy breakEnd
1 parent 01a2ec0 commit c76b9aa

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Data/Text/Lazy.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-# OPTIONS_GHC -fno-warn-orphans #-}
2-
{-# LANGUAGE BangPatterns, MagicHash, CPP, TypeFamilies #-}
2+
{-# LANGUAGE BangPatterns, MagicHash, CPP, OverloadedStrings, TypeFamilies #-}
33
#if __GLASGOW_HASKELL__ >= 702
44
{-# LANGUAGE Trustworthy #-}
55
#endif
@@ -1411,8 +1411,15 @@ break p t0 = break' t0
14111411
-- >>> T.breakEnd (=='0') "180cm"
14121412
-- ("180","cm")
14131413
breakEnd :: (Char -> Bool) -> Text -> (Text, Text)
1414-
breakEnd p src = let (a,b) = break p (reverse src)
1415-
in (reverse b, reverse a)
1414+
breakEnd p src = breakEnd' (reverseSpine src) where
1415+
reverseSpine = go Empty where
1416+
go res Empty = res
1417+
go res (Chunk t ts) = go (Chunk t res) ts
1418+
breakEnd' = go Empty where
1419+
go r Empty = (empty, r)
1420+
go r (Chunk t ts) = case T.breakEnd p t of
1421+
("", _) -> go (Chunk t r) ts
1422+
(l, r') -> (reverseSpine (Chunk l ts), Chunk r' r)
14161423
{-# INLINE breakEnd #-}
14171424

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

0 commit comments

Comments
 (0)