on master help sign in
Get rid of the elem function.

--HG-- extra : convert_revision : 74db040a17a6b7623b2a23c9a4ac0cdf8133ddde

commita2a45248e6ce7363cbf99c29896940bdef7e99b0 authorBryan O'Sullivan <bos@serpentine.com> dateFri 9 Oct 2009, 03:18 (17 years ago) parent8c1753f
3 files changed+10−21
Data/Text.hs+10−11 Data/Text/Lazy.hs−6 tests/Properties.hs−4
Data/Text.hs+10−11
@@ -140,7 +140,6 @@ module Data.Text
140140 , isInfixOf
141141
142142 -- * Searching
143− , elem
144143 , filter
145144 , find
146145 , findBy
@@ -966,14 +965,6 @@ chunksOf k = go
966965-- ----------------------------------------------------------------------------
967966-- * Searching
968967
969−-------------------------------------------------------------------------------
970−-- ** Searching by equality
971−
972−-- | /O(n)/ 'elem' is the 'Text' membership predicate.
973−elem :: Char -> Text -> Bool
974−elem c t = S.elem c (stream t)
975−{-# INLINE elem #-}
976−
977968-------------------------------------------------------------------------------
978969-- ** Searching with a predicate
979970
@@ -1222,8 +1213,16 @@ isSuffixOf a@(Text _aarr _aoff alen) b@(Text barr boff blen) =
12221213-- In (unlikely) bad cases, this function's time complexity degrades
12231214-- towards /O(n*m)/.
12241215isInfixOf :: Text -> Text -> Bool
1225−isInfixOf pat src = null pat || (not . L.null $ indices pat src)
1226−{-# INLINE isInfixOf #-}
1216+isInfixOf needle haystack
1217+ | null needle = True
1218+ | isSingleton needle = S.elem (unsafeHead needle) . S.stream $ haystack
1219+ | otherwise = not . L.null . indices needle $ haystack
1220+{-# INLINE [1] isInfixOf #-}
1221+
1222+{-# RULES
1223+"TEXT isInfixOf/singleton -> S.elem/S.stream" [~1] forall n h.
1224+ isInfixOf (singleton n) h = S.elem n (S.stream h)
1225+ #-}
12271226
12281227emptyError :: String -> a
12291228emptyError fun = P.error ("Data.Text." ++ fun ++ ": empty input")
Data/Text/Lazy.hs−6
@@ -144,7 +144,6 @@ module Data.Text.Lazy
144144 , isInfixOf
145145
146146 -- * Searching
147− , elem
148147 , filter
149148 , findBy
150149 , partitionBy
@@ -1043,11 +1042,6 @@ isInfixOf needle haystack = L.any (isPrefixOf needle) (tails haystack)
10431042{-# INLINE isInfixOf #-}
10441043-- TODO: a better implementation
10451044
1046−-- | /O(n)/ 'elem' is the 'Text' membership predicate.
1047−elem :: Char -> Text -> Bool
1048−elem c t = S.elem c (stream t)
1049−{-# INLINE elem #-}
1050−
10511045-- | /O(n)/ 'filter', applied to a predicate and a 'Text',
10521046-- returns a 'Text' containing those characters that satisfy the
10531047-- predicate.
tests/Properties.hs−4
@@ -466,8 +466,6 @@ t_isInfixOf s = L.isInfixOf s `eqP` T.isInfixOf (packS s)
466466tl_isInfixOf s = L.isInfixOf s `eqP` TL.isInfixOf (packS s)
467467
468468sf_elem p c = (L.elem c . L.filter p) `eqP` (S.elem c . S.filter p)
469−t_elem c = L.elem c `eqP` T.elem c
470−tl_elem c = L.elem c `eqP` TL.elem c
471469sf_filter q p = (L.filter p . L.filter q) `eqP` (unpackS . S.filter p . S.filter q)
472470t_filter p = L.filter p `eqP` (unpackS . T.filter p)
473471tl_filter p = L.filter p `eqP` (unpackS . TL.filter p)
@@ -832,8 +830,6 @@ tests = [
832830
833831 testGroup "searching" [
834832 testProperty "sf_elem" sf_elem,
835− testProperty "t_elem" t_elem,
836− testProperty "tl_elem" tl_elem,
837833 testProperty "sf_filter" sf_filter,
838834 testProperty "t_filter" t_filter,
839835 testProperty "tl_filter" tl_filter,