on master help sign in
Remove the old version of replace
1aa063bBryan O'Sullivan
Data/Text.hs+7−15
@@ -73,7 +73,6 @@ module Data.Text
73 , transpose
73 , transpose
74 , reverse
74 , reverse
75 , replace
75 , replace
76− , replace2
77
76
78 -- ** Case conversion
77 -- ** Case conversion
79 -- $case
78 -- $case
@@ -617,19 +616,12 @@ reverse t = S.reverse (stream t)
617--
616--
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
623− -> Text
624−replace s d = intercalate d . splitOn s
625−{-# INLINE replace #-}
626−
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
640 x = do
632 x = do
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
benchmarks/haskell/Benchmarks/Replace.hs−1
@@ -28,7 +28,6 @@ benchmark fp pat sub = do
28 !b = T.encodeUtf8 t
28 !b = T.encodeUtf8 t
29 return $ bgroup "Replace" [
29 return $ bgroup "Replace" [
30 bench "Text" $ nf (T.length . T.replace tpat tsub) t
30 bench "Text" $ nf (T.length . T.replace tpat tsub) t
31− , bench "Text2" $ nf (T.length . T.replace2 tpat tsub) t
32 , bench "ByteString" $ nf (BL.length . B.replace bpat bsub) b
31 , bench "ByteString" $ nf (BL.length . B.replace bpat bsub) b
33 , bench "LazyText" $ nf (TL.length . TL.replace tlpat tlsub) tl
32 , bench "LazyText" $ nf (TL.length . TL.replace tlpat tlsub) tl
34 , bench "LazyByteString" $ nf (BL.length . BL.replace blpat blsub) bl
33 , bench "LazyByteString" $ nf (BL.length . BL.replace blpat blsub) bl
tests/Tests/Properties.hs−5
@@ -234,10 +234,6 @@ t_reverse_short n = L.reverse `eqP` (unpackS . S.reverse . shorten n . S.stream)
234
234
235t_replace s d = (L.intercalate d . splitOn s) `eqP`
235t_replace s d = (L.intercalate d . splitOn s) `eqP`
236 (unpackS . T.replace (T.pack s) (T.pack d))
236 (unpackS . T.replace (T.pack s) (T.pack d))
237−t_replace2 (NotEmpty s0) (NotEmpty d0) (NotEmpty w0) =
238− T.replace s d w =^= T.replace2 s d w
239− where s = f s0; d = f d0; w = f w0
240− f = T.tail . T.pack
241tl_replace s d = (L.intercalate d . splitOn s) `eqP`
237tl_replace s d = (L.intercalate d . splitOn s) `eqP`
242 (unpackS . TL.replace (TL.pack s) (TL.pack d))
238 (unpackS . TL.replace (TL.pack s) (TL.pack d))
243
239
@@ -900,7 +896,6 @@ tests =
900 testProperty "tl_reverse" tl_reverse,
896 testProperty "tl_reverse" tl_reverse,
901 testProperty "t_reverse_short" t_reverse_short,
897 testProperty "t_reverse_short" t_reverse_short,
902 testProperty "t_replace" t_replace,
898 testProperty "t_replace" t_replace,
903− testProperty "t_replace2" t_replace2,
904 testProperty "tl_replace" tl_replace,
899 testProperty "tl_replace" tl_replace,
905
900
906 testGroup "case conversion" [
901 testGroup "case conversion" [