on master help sign in
Get rid of the elem function.
a2a4524Bryan O'Sullivan
Data/Text.hs+10−11
@@ -140,7 +140,6 @@ module Data.Text
140 , isInfixOf
140 , isInfixOf
141
141
142 -- * Searching
142 -- * Searching
143− , elem
144 , filter
143 , filter
145 , find
144 , find
146 , findBy
145 , findBy
@@ -966,14 +965,6 @@ chunksOf k = go
966-- ----------------------------------------------------------------------------
965-- ----------------------------------------------------------------------------
967-- * Searching
966-- * Searching
968
967
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−
977-------------------------------------------------------------------------------
968-------------------------------------------------------------------------------
978-- ** Searching with a predicate
969-- ** Searching with a predicate
979
970
@@ -1222,8 +1213,16 @@ isSuffixOf a@(Text _aarr _aoff alen) b@(Text barr boff blen) =
1222-- In (unlikely) bad cases, this function's time complexity degrades
1213-- In (unlikely) bad cases, this function's time complexity degrades
1223-- towards /O(n*m)/.
1214-- towards /O(n*m)/.
1224isInfixOf :: Text -> Text -> Bool
1215isInfixOf :: Text -> Text -> Bool
1225−isInfixOf pat src = null pat || (not . L.null $ indices pat src)
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
1226−{-# INLINE isInfixOf #-}
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+ #-}
1227
1226
1228emptyError :: String -> a
1227emptyError :: String -> a
1229emptyError fun = P.error ("Data.Text." ++ fun ++ ": empty input")
1228emptyError fun = P.error ("Data.Text." ++ fun ++ ": empty input")
Data/Text/Lazy.hs−6
@@ -144,7 +144,6 @@ module Data.Text.Lazy
144 , isInfixOf
144 , isInfixOf
145
145
146 -- * Searching
146 -- * Searching
147− , elem
148 , filter
147 , filter
149 , findBy
148 , findBy
150 , partitionBy
149 , partitionBy
@@ -1043,11 +1042,6 @@ isInfixOf needle haystack = L.any (isPrefixOf needle) (tails haystack)
1043{-# INLINE isInfixOf #-}
1042{-# INLINE isInfixOf #-}
1044-- TODO: a better implementation
1043-- TODO: a better implementation
1045
1044
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−
1051-- | /O(n)/ 'filter', applied to a predicate and a 'Text',
1045-- | /O(n)/ 'filter', applied to a predicate and a 'Text',
1052-- returns a 'Text' containing those characters that satisfy the
1046-- returns a 'Text' containing those characters that satisfy the
1053-- predicate.
1047-- predicate.
tests/Properties.hs−4
@@ -466,8 +466,6 @@ t_isInfixOf s = L.isInfixOf s `eqP` T.isInfixOf (packS s)
466tl_isInfixOf s = L.isInfixOf s `eqP` TL.isInfixOf (packS s)
466tl_isInfixOf s = L.isInfixOf s `eqP` TL.isInfixOf (packS s)
467
467
468sf_elem p c = (L.elem c . L.filter p) `eqP` (S.elem c . S.filter p)
468sf_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
471sf_filter q p = (L.filter p . L.filter q) `eqP` (unpackS . S.filter p . S.filter q)
469sf_filter q p = (L.filter p . L.filter q) `eqP` (unpackS . S.filter p . S.filter q)
472t_filter p = L.filter p `eqP` (unpackS . T.filter p)
470t_filter p = L.filter p `eqP` (unpackS . T.filter p)
473tl_filter p = L.filter p `eqP` (unpackS . TL.filter p)
471tl_filter p = L.filter p `eqP` (unpackS . TL.filter p)
@@ -832,8 +830,6 @@ tests = [
832
830
833 testGroup "searching" [
831 testGroup "searching" [
834 testProperty "sf_elem" sf_elem,
832 testProperty "sf_elem" sf_elem,
835− testProperty "t_elem" t_elem,
836− testProperty "tl_elem" tl_elem,
837 testProperty "sf_filter" sf_filter,
833 testProperty "sf_filter" sf_filter,
838 testProperty "t_filter" t_filter,
834 testProperty "t_filter" t_filter,
839 testProperty "tl_filter" tl_filter,
835 testProperty "tl_filter" tl_filter,