@@ -101,7 +101,6 @@ module Data.Text.Lazy
102 -- ** Generation and unfolding
102 -- ** Generation and unfolding
103 , replicate
103 , replicate
105 , unfoldr
104 , unfoldr
106 , unfoldrN
105 , unfoldrN
@@ -330,6 +329,12 @@ null _ = False
330 S.null (stream t) = null t
329 S.null (stream t) = null t
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 #-}
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
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 #-}
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 #-}
643"LAZY TEXT replicate/singleton -> replicateChar" [~1] forall n c.
651"LAZY TEXT replicate/singleton -> replicateChar" [~1] forall n c.