@@ -228,7 +228,7 @@ import Prelude (Char, Bool(..), Int, Maybe(..), String,
228228 Eq , (==) , (/=) , Ord (.. ), Ordering (.. ), (++) ,
229229 Monad (.. ), pure , Read (.. ), Show ,
230230 (&&) , (||) , (+) , (-) , (.) , ($) , ($!) , (>>) ,
231- not , return , otherwise , quot )
231+ fst , not , return , otherwise , quot , snd )
232232import Control.DeepSeq (NFData (rnf ))
233233#if defined(ASSERTS)
234234import Control.Exception (assert )
@@ -273,7 +273,7 @@ import qualified Data.Text.Lazy as L
273273#endif
274274import Data.Word (Word8 )
275275import Foreign.C.Types
276- import GHC.Base (eqInt , neInt , gtInt , geInt , ltInt , leInt )
276+ import GHC.Base (eqChar , neChar , eqInt , neInt , gtInt , geInt , ltInt , leInt )
277277import qualified GHC.Exts as Exts
278278import GHC.Int (Int8 )
279279import GHC.Stack (HasCallStack )
@@ -1522,6 +1522,13 @@ takeWhile p t@(Text arr off len) = loop 0
15221522 where Iter c d = iter t i
15231523{-# INLINE [1] takeWhile #-}
15241524
1525+ {-# RULES
1526+ "TEXT takeWhile (c `neChar`) -> fst . breakOn (singleton c)" forall c.
1527+ takeWhile (c `neChar`) = fst . breakOn (singleton c)
1528+ "TEXT takeWhile (`neChar` c) -> fst . breakOn (singleton c)" forall c.
1529+ takeWhile (`neChar` c) = fst . breakOn (singleton c)
1530+ #-}
1531+
15251532-- | /O(n)/ 'takeWhileEnd', applied to a predicate @p@ and a 'Text',
15261533-- returns the longest suffix (possibly empty) of elements that
15271534-- satisfy @p@.
@@ -1549,6 +1556,13 @@ dropWhile p t@(Text arr off len) = loop 0 0
15491556 where Iter c d = iter t i
15501557{-# INLINE [1] dropWhile #-}
15511558
1559+ {-# RULES
1560+ "TEXT dropWhile (c `neChar`) -> snd . breakOn (singleton c)" forall c.
1561+ dropWhile (c `neChar`) = snd . breakOn (singleton c)
1562+ "TEXT dropWhile (`neChar` c) -> snd . breakOn (singleton c)" forall c.
1563+ dropWhile (`neChar` c) = snd . breakOn (singleton c)
1564+ #-}
1565+
15521566-- | /O(n)/ 'dropWhileEnd' @p@ @t@ returns the prefix remaining after
15531567-- dropping characters that satisfy the predicate @p@ from the end of
15541568-- @t@.
@@ -1615,7 +1629,14 @@ splitAt n t@(Text arr off len)
16151629span :: (Char -> Bool ) -> Text -> (Text , Text )
16161630span p t = case span_ p t of
16171631 (# hd,tl # ) -> (hd,tl)
1618- {-# INLINE span #-}
1632+ {-# INLINE [1] span #-}
1633+
1634+ {-# RULES
1635+ "TEXT span (c `neChar`) -> breakOn (singleton c)" forall c.
1636+ span (c `neChar`) = breakOn (singleton c)
1637+ "TEXT span (`neChar` c) -> breakOn (singleton c)" forall c.
1638+ span (`neChar` c) = breakOn (singleton c)
1639+ #-}
16191640
16201641-- | /O(n)/ 'break' is like 'span', but the prefix returned is
16211642-- over elements that fail the predicate @p@.
@@ -1624,7 +1645,14 @@ span p t = case span_ p t of
16241645-- ("180","cm")
16251646break :: (Char -> Bool ) -> Text -> (Text , Text )
16261647break p = span (not . p)
1627- {-# INLINE break #-}
1648+ {-# INLINE [1] break #-}
1649+
1650+ {-# RULES
1651+ "TEXT break (c `eqChar`) -> breakOn (singleton c)" forall c.
1652+ break (c `eqChar`) = breakOn (singleton c)
1653+ "TEXT break (`eqChar` c) -> breakOn (singleton c)" forall c.
1654+ break (`eqChar` c) = breakOn (singleton c)
1655+ #-}
16281656
16291657spanEnd :: (Char -> Bool ) -> Text -> (Text , Text )
16301658spanEnd = coerce (spanEndM :: (Char -> Identity Bool ) -> Text -> Identity (Text , Text ))
0 commit comments