Commits

Bryan O'Sullivan committed c3799e9

Fix up lazy concat and concatMap.

Comments (0)

Files changed (1)

 foldr1 f t = S.foldr1 f (stream t)
 {-# INLINE foldr1 #-}
 
--- | /O(n)/ Concatenate a list of 'Text's. Subject to array fusion.
+-- | /O(n)/ Concatenate a list of 'Text's.
 concat :: [Text] -> Text
-concat ts = unstream (S.concat (L.map stream ts))
+concat = to
+  where
+    go Empty        css = to css
+    go (Chunk c cs) css = Chunk c (go cs css)
+    to []               = Empty
+    to (cs:css)         = go cs css
 {-# INLINE concat #-}
 
 -- | /O(n)/ Map a function over a 'Text' that results in a 'Text', and
--- concatenate the results.  This function is subject to array fusion.
---
--- Note: if in 'concatMap' @f@ @t@, @f@ is defined in terms of fusible
--- functions, it will also be fusible.
+-- concatenate the results.
 concatMap :: (Char -> Text) -> Text -> Text
-concatMap f t = unstream (S.concatMap (stream . f) (stream t))
+concatMap f = concat . foldr ((:) . f) []
 {-# INLINE concatMap #-}
 
 -- | /O(n)/ 'any' @p@ @t@ determines whether any character in the