on master help sign in
Drop replicateChar from the public API.
c8a85dcBryan O'Sullivan
Data/Text.hs+4−2
@@ -97,7 +97,6 @@ module Data.Text
97
97
98 -- ** Generation and unfolding
98 -- ** Generation and unfolding
99 , replicate
99 , replicate
100− , replicateChar
101 , unfoldr
100 , unfoldr
102 , unfoldrN
101 , unfoldrN
103
102
@@ -660,7 +659,9 @@ mapAccumR f s t = case uncons t of
660-- | /O(n*m)/ 'replicate' @n@ @t@ is a 'Text' consisting of the input
659-- | /O(n*m)/ 'replicate' @n@ @t@ is a 'Text' consisting of the input
661-- @t@ repeated @n@ times. Subject to fusion.
660-- @t@ repeated @n@ times. Subject to fusion.
662replicate :: Int -> Text -> Text
661replicate :: Int -> Text -> Text
662+replicate n t
663+ | isSingleton t = replicateChar n (unsafeHead t)
663−replicate n t = unstream (S.replicateI (fromIntegral n) (S.stream t))
664+ | otherwise = unstream (S.replicateI (fromIntegral n) (S.stream t))
664{-# INLINE [1] replicate #-}
665{-# INLINE [1] replicate #-}
665
666
666{-# RULES
667{-# RULES
@@ -672,6 +673,7 @@ replicate n t = unstream (S.replicateI (fromIntegral n) (S.stream t))
672-- value of every element. Subject to fusion.
673-- value of every element. Subject to fusion.
673replicateChar :: Int -> Char -> Text
674replicateChar :: Int -> Char -> Text
674replicateChar n c = unstream (S.replicateCharI n c)
675replicateChar n c = unstream (S.replicateCharI n c)
676+{-# INLINE replicateChar #-}
675
677
676-- | /O(n)/, where @n@ is the length of the result. The 'unfoldr'
678-- | /O(n)/, where @n@ is the length of the result. The 'unfoldr'
677-- function is analogous to the List 'L.unfoldr'. 'unfoldr' builds a
679-- function is analogous to the List 'L.unfoldr'. 'unfoldr' builds a
Data/Text/Lazy.hs+10−2
@@ -101,7 +101,6 @@ module Data.Text.Lazy
101
101
102 -- ** Generation and unfolding
102 -- ** Generation and unfolding
103 , replicate
103 , replicate
104− , replicateChar
105 , unfoldr
104 , unfoldr
106 , unfoldrN
105 , unfoldrN
107
106
@@ -330,6 +329,12 @@ null _ = False
330 S.null (stream t) = null t
329 S.null (stream t) = null t
331 #-}
330 #-}
332
331
332+-- | /O(1)/ Tests whether a 'Text' contains exactly one character.
333+-- Subject to fusion.
334+isSingleton :: Text -> Bool
335+isSingleton = S.isSingleton . stream
336+{-# INLINE isSingleton #-}
337+
333-- | /O(1)/ Returns the last character of a 'Text', which must be
338-- | /O(1)/ Returns the last character of a 'Text', which must be
334-- non-empty. Subject to array fusion.
339-- non-empty. Subject to array fusion.
335last :: Text -> Char
340last :: Text -> Char
@@ -631,13 +636,16 @@ mapAccumR f s t = case uncons t of
631-- | /O(n*m)/ 'replicate' @n@ @t@ is a 'Text' consisting of the input
636-- | /O(n*m)/ 'replicate' @n@ @t@ is a 'Text' consisting of the input
632-- @t@ repeated @n@ times. Subject to fusion.
637-- @t@ repeated @n@ times. Subject to fusion.
633replicate :: Int64 -> Text -> Text
638replicate :: Int64 -> Text -> Text
639+replicate n t
640+ | isSingleton t = replicateChar n (head t)
634−replicate n t = unstream (S.replicateI n (S.stream t))
641+ | otherwise = unstream (S.replicateI n (S.stream t))
635{-# INLINE replicate #-}
642{-# INLINE replicate #-}
636
643
637-- | /O(n)/ 'replicateChar' @n@ @c@ is a 'Text' of length @n@ with @c@ the
644-- | /O(n)/ 'replicateChar' @n@ @c@ is a 'Text' of length @n@ with @c@ the
638-- value of every element. Subject to fusion.
645-- value of every element. Subject to fusion.
639replicateChar :: Int64 -> Char -> Text
646replicateChar :: Int64 -> Char -> Text
640replicateChar n c = unstream (S.replicateCharI n c)
647replicateChar n c = unstream (S.replicateCharI n c)
648+{-# INLINE replicateChar #-}
641
649
642{-# RULES
650{-# RULES
643"LAZY TEXT replicate/singleton -> replicateChar" [~1] forall n c.
651"LAZY TEXT replicate/singleton -> replicateChar" [~1] forall n c.