Skip to content

Commit c53b59f

Browse files
committed
Text: flip isSubsequenceOf
Previous argument order was alike `lookup` argument order mistake, when key cached (compiler saturates function) across DBs. Efficient use of the function is to all it once (per pattern) on the whole contents. So the contents should be cached first, and the search patterns are switchable.
1 parent 813989c commit c53b59f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Data/Text.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,20 +1883,20 @@ isInfixOf needle haystack
18831883
{-# INLINE [1] isInfixOf #-}
18841884

18851885
-- | The 'isSubsequenceOf' function takes two 'Text's and returns
1886-
-- 'True' iff the first is a subsequence of a second.
1887-
-- (characters of the first argument appear in same sequential order in
1888-
-- the second, to say if first argument that can be derived by deleting some
1889-
-- or no elements from the second).
1886+
-- 'True' iff the second is a subsequence of the first.
1887+
-- (characters of the second argument appear in same sequential order in
1888+
-- the first, to say if second argument can be derived by deleting some
1889+
-- or no elements from the first).
18901890
isSubsequenceOf :: Text -> Text -> Bool
1891-
isSubsequenceOf sf tf
1891+
isSubsequenceOf tf sf
18921892
| length sf > length tf = False
1893-
| otherwise = subseqOf sf tf
1893+
| otherwise = subseqOf tf sf
18941894
where
1895-
subseqOf s t
1895+
subseqOf t s
18961896
| null s = True
18971897
| null t = False
1898-
| unsafeHead s == unsafeHead t = subseqOf (unsafeTail s) (unsafeTail t)
1899-
| otherwise = subseqOf s $ unsafeTail t
1898+
| unsafeHead s == unsafeHead t = subseqOf (unsafeTail t) (unsafeTail s)
1899+
| otherwise = subseqOf (unsafeTail t) s
19001900

19011901
-------------------------------------------------------------------------------
19021902
-- * View patterns

0 commit comments

Comments
 (0)