@@ -140,7 +140,6 @@ module Data.Text
140 , isInfixOf
140 , isInfixOf
142 -- * Searching
142 -- * Searching
@@ -966,14 +965,6 @@ chunksOf k = go
966-- ----------------------------------------------------------------------------
965-- ----------------------------------------------------------------------------
967-- * Searching
966-- * Searching
969−-------------------------------------------------------------------------------
970−-- ** Searching by equality
972−-- | /O(n)/ 'elem' is the 'Text' membership predicate.
973−elem :: Char -> Text -> Bool
974−elem c t = S.elem c (stream t)
977-------------------------------------------------------------------------------
968-------------------------------------------------------------------------------
978-- ** Searching with a predicate
969-- ** Searching with a predicate
@@ -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 #-}
1223+"TEXT isInfixOf/singleton -> S.elem/S.stream" [~1] forall n h.
1224+ isInfixOf (singleton n) h = S.elem n (S.stream h)
1228emptyError :: String -> a
1227emptyError :: String -> a
1229emptyError fun = P.error ("Data.Text." ++ fun ++ ": empty input")
1228emptyError fun = P.error ("Data.Text." ++ fun ++ ": empty input")