on master help sign in
Drop replicateChar from the public API.

--HG-- extra : convert_revision : 122b009a6a5c267a3753e8b2849a3f284d777da8

commitc8a85dc34e24e7b3aebc22a782f2957734b5d830 authorBryan O'Sullivan <bos@serpentine.com> dateTue 6 Oct 2009, 23:25 (17 years ago) parentfa33b75
2 files changed+14−4
Data/Text.hs+4−2 Data/Text/Lazy.hs+10−2
Data/Text.hs+4−2
@@ -97,7 +97,6 @@ module Data.Text
9797
9898 -- ** Generation and unfolding
9999 , replicate
100− , replicateChar
101100 , unfoldr
102101 , unfoldrN
103102
@@ -660,7 +659,9 @@ mapAccumR f s t = case uncons t of
660659-- | /O(n*m)/ 'replicate' @n@ @t@ is a 'Text' consisting of the input
661660-- @t@ repeated @n@ times. Subject to fusion.
662661replicate :: Int -> Text -> Text
663−replicate n t = unstream (S.replicateI (fromIntegral n) (S.stream t))
662+replicate n t
663+ | isSingleton t = replicateChar n (unsafeHead t)
664+ | otherwise = unstream (S.replicateI (fromIntegral n) (S.stream t))
664665{-# INLINE [1] replicate #-}
665666
666667{-# RULES
@@ -672,6 +673,7 @@ replicate n t = unstream (S.replicateI (fromIntegral n) (S.stream t))
672673-- value of every element. Subject to fusion.
673674replicateChar :: Int -> Char -> Text
674675replicateChar n c = unstream (S.replicateCharI n c)
676+{-# INLINE replicateChar #-}
675677
676678-- | /O(n)/, where @n@ is the length of the result. The 'unfoldr'
677679-- 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
101101
102102 -- ** Generation and unfolding
103103 , replicate
104− , replicateChar
105104 , unfoldr
106105 , unfoldrN
107106
@@ -330,6 +329,12 @@ null _ = False
330329 S.null (stream t) = null t
331330 #-}
332331
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+
333338-- | /O(1)/ Returns the last character of a 'Text', which must be
334339-- non-empty. Subject to array fusion.
335340last :: Text -> Char
@@ -631,13 +636,16 @@ mapAccumR f s t = case uncons t of
631636-- | /O(n*m)/ 'replicate' @n@ @t@ is a 'Text' consisting of the input
632637-- @t@ repeated @n@ times. Subject to fusion.
633638replicate :: Int64 -> Text -> Text
634−replicate n t = unstream (S.replicateI n (S.stream t))
639+replicate n t
640+ | isSingleton t = replicateChar n (head t)
641+ | otherwise = unstream (S.replicateI n (S.stream t))
635642{-# INLINE replicate #-}
636643
637644-- | /O(n)/ 'replicateChar' @n@ @c@ is a 'Text' of length @n@ with @c@ the
638645-- value of every element. Subject to fusion.
639646replicateChar :: Int64 -> Char -> Text
640647replicateChar n c = unstream (S.replicateCharI n c)
648+{-# INLINE replicateChar #-}
641649
642650{-# RULES
643651"LAZY TEXT replicate/singleton -> replicateChar" [~1] forall n c.