@@ -919,8 +919,8 @@ tails ts@(Chunk t ts')
919-- copies to create substrings; they just construct new 'Text's that
919-- copies to create substrings; they just construct new 'Text's that
920-- are slices of the original.
920-- are slices of the original.
922−-- | /O(m)*O(n)/ Break a 'Text' into pieces separated by the first
922+-- | /O(m+n)/ Break a 'Text' into pieces separated by the first
923−-- 'Text' argument, consuming the delimiter. An empty delimiter is
923+-- 'Text' argument, consuming the delimiter. An empty delimiter is
924-- invalid, and will cause an error to be raised.
924-- invalid, and will cause an error to be raised.
926-- Examples:
926-- Examples:
@@ -933,21 +933,20 @@ tails ts@(Chunk t ts')
934-- > intercalate s . split s == id
934-- > intercalate s . split s == id
935-- > split (singleton c) == splitBy (==c)
935-- > split (singleton c) == splitBy (==c)
937+-- In (unlikely) bad cases, this function's time complexity degrades
936split :: Text -- ^ Text to split on
939split :: Text -- ^ Text to split on
937 -> Text -- ^ Input text
940 -> Text -- ^ Input text
938 -> [Text]
941 -> [Text]
939−split pat src0
942+split pat src
940− | l == 0 = emptyError "split"
943+ | null pat = emptyError "split"
941− | l == 1 = splitBy (== (head pat)) src0
944+ | isSingleton pat = splitBy (== head pat) src
942− | otherwise = go src0
945+ | otherwise = go 0 (indices pat src) src
944− l = length pat
947+ go _ [] cs = [cs]
945− go src = search 0 src
948+ go !s (x:xs) cs = let h :*: t = splitAtWord (x-s) cs
946− where
949+ in h : go (s+x) xs t
948− | null s = [src] -- not found
949− | pat `isPrefixOf` s = take n src : go (drop l s)
950− | otherwise = search (n+1) (tail s)
951{-# INLINE [1] split #-}
950{-# INLINE [1] split #-}