@@ -73,7 +73,6 @@ module Data.Text
73 , transpose
73 , transpose
78 -- ** Case conversion
77 -- ** Case conversion
@@ -617,19 +616,12 @@ reverse t = S.reverse (stream t)
618-- In (unlikely) bad cases, this function's time complexity degrades
617-- In (unlikely) bad cases, this function's time complexity degrades
619-- towards /O(n*m)/.
618-- towards /O(n*m)/.
620−replace :: Text -- ^ Text to search for
619+replace :: Text -> Text -> Text -> Text
621− -> Text -- ^ Replacement text
622− -> Text -- ^ Input text
624−replace s d = intercalate d . splitOn s
625−{-# INLINE replace #-}
627−replace2 :: Text -> Text -> Text -> Text
628−replace2 needle@(Text _ _ neeLen)
620+replace needle@(Text _ _ neeLen)
629− r@(Text repArr repOff repLen)
621+ (Text repArr repOff repLen)
630− haystack@(Text hayArr hayOff hayLen)
622+ haystack@(Text hayArr hayOff hayLen)
631− | neeLen == 0 = emptyError "replace2"
623+ | neeLen == 0 = emptyError "replace"
632− | len < 0 = overflowError "replace2"
624+ | len < 0 = overflowError "replace"
633 | len == 0 = empty
625 | len == 0 = empty
634 | L.null ixs = haystack
626 | L.null ixs = haystack
635 | otherwise = Text (A.run x) 0 len
627 | otherwise = Text (A.run x) 0 len
@@ -639,7 +631,7 @@ replace2 needle@(Text _ _ neeLen)
639 len = hayLen - (neeLen - repLen) * cnt
631 len = hayLen - (neeLen - repLen) * cnt
641 marr <- A.new len
633 marr <- A.new len
642− let loop is0@(i:is) o d = do
634+ let loop (i:is) o d = do
643 let d0 = d + i - o
635 let d0 = d + i - o
644 d1 = d0 + repLen
636 d1 = d0 + repLen
645 A.copyI marr d hayArr (hayOff+o) d0
637 A.copyI marr d hayArr (hayOff+o) d0