Skip to content

Commit d4da7fa

Browse files
committed
Remove rules for takeWhileEnd and dropWhileEnd
it would previously replace `takeWhileEnd p` with S.reverse . S.takeWhile p . S.reverseStream But `S.reverse` can only fuse with its argument, and `S.reverseStream` only fuses with its consumer. So all possible fusion is within this pipeline, and in the best case we obtain a direct implementation. There might be some value in this if we had a `S.reverseStream/S.reverse` rule, so that in multiple chained invocations of `takeWhileEnd` we could eliminate some intermediat steps. But no such rule exists at the moment.
1 parent 009fba2 commit d4da7fa

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

Data/Text.hs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ takeWhile p t@(Text arr off len) = loop 0
12351235

12361236
-- | /O(n)/ 'takeWhileEnd', applied to a predicate @p@ and a 'Text',
12371237
-- returns the longest suffix (possibly empty) of elements that
1238-
-- satisfy @p@. Subject to fusion.
1238+
-- satisfy @p@.
12391239
-- Examples:
12401240
--
12411241
-- >>> takeWhileEnd (=='o') "foo"
@@ -1250,13 +1250,6 @@ takeWhileEnd p t@(Text arr off len) = loop (len-1) len
12501250
where (c,d) = reverseIter t i
12511251
{-# INLINE [1] takeWhileEnd #-}
12521252

1253-
{-# RULES
1254-
"TEXT takeWhileEnd -> fused" [~1] forall p t.
1255-
takeWhileEnd p t = S.reverse (S.takeWhile p (S.reverseStream t))
1256-
"TEXT takeWhileEnd -> unfused" [1] forall p t.
1257-
S.reverse (S.takeWhile p (S.reverseStream t)) = takeWhileEnd p t
1258-
#-}
1259-
12601253
-- | /O(n)/ 'dropWhile' @p@ @t@ returns the suffix remaining after
12611254
-- 'takeWhile' @p@ @t@. Subject to fusion.
12621255
dropWhile :: (Char -> Bool) -> Text -> Text
@@ -1276,7 +1269,7 @@ dropWhile p t@(Text arr off len) = loop 0 0
12761269

12771270
-- | /O(n)/ 'dropWhileEnd' @p@ @t@ returns the prefix remaining after
12781271
-- dropping characters that satisfy the predicate @p@ from the end of
1279-
-- @t@. Subject to fusion.
1272+
-- @t@.
12801273
--
12811274
-- Examples:
12821275
--
@@ -1290,13 +1283,6 @@ dropWhileEnd p t@(Text arr off len) = loop (len-1) len
12901283
where (c,d) = reverseIter t i
12911284
{-# INLINE [1] dropWhileEnd #-}
12921285

1293-
{-# RULES
1294-
"TEXT dropWhileEnd -> fused" [~1] forall p t.
1295-
dropWhileEnd p t = S.reverse (S.dropWhile p (S.reverseStream t))
1296-
"TEXT dropWhileEnd -> unfused" [1] forall p t.
1297-
S.reverse (S.dropWhile p (S.reverseStream t)) = dropWhileEnd p t
1298-
#-}
1299-
13001286
-- | /O(n)/ 'dropAround' @p@ @t@ returns the substring remaining after
13011287
-- dropping characters that satisfy the predicate @p@ from both the
13021288
-- beginning and end of @t@. Subject to fusion.

0 commit comments

Comments
 (0)