@@ -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")