@@ -175,7 +175,7 @@ module Data.Text.Lazy
175175
176176import Prelude (Char, Bool(..), Maybe(..), String,
177177 Eq(..), Ord(..), Ordering(..), Read(..), Show(..),
178− (&&), (+), (-), (.), ($), (++),
178+ (&&), (||), (+), (-), (.), ($), (++),
179179 div, error, flip, fromIntegral, not, otherwise)
180180import qualified Prelude as P
181181#if defined(HAVE_DEEPSEQ)
@@ -721,9 +721,12 @@ mapAccumR f = go
721721-- | /O(n*m)/ 'replicate' @n@ @t@ is a 'Text' consisting of the input
722722-- @t@ repeated @n@ times.
723723replicate :: Int64 -> Text -> Text
724−replicate n t = concat (rep 0)
725− where rep i | i >= n = []
726− | otherwise = t : rep (i+1)
724+replicate n t
725+ | null t || n <= 0 = empty
726+ | isSingleton t = replicateChar n (head t)
727+ | otherwise = concat (rep 0)
728+ where rep !i | i >= n = []
729+ | otherwise = t : rep (i+1)
727730{-# INLINE replicate #-}
728731
729732-- | /O(n)/ 'replicateChar' @n@ @c@ is a 'Text' of length @n@ with @c@ the