aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Pretty.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-03-28 13:51:15 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-03-28 13:51:15 -0700
commit7fa5fbed9e0440694e9c52a8dc83f3e4f29c8a96 (patch)
tree3015d7ef16559c3c40e6f1db2644bc5bac00565e /src/Text/Pandoc/Pretty.hs
parentb87a3efb93a7354c53117fa4ba6d43d2b5746ee9 (diff)
downloadpandoc-7fa5fbed9e0440694e9c52a8dc83f3e4f29c8a96.tar.gz
Use strict instead of lazy sum.
sum is lazy; replace with `foldl' (+) 0` to avoid stack overflow in Text.Pandoc.Pretty with very long strings. Closes #5401.
Diffstat (limited to 'src/Text/Pandoc/Pretty.hs')
-rw-r--r--src/Text/Pandoc/Pretty.hs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Pretty.hs b/src/Text/Pandoc/Pretty.hs
index 2d7a3a725..ad223274e 100644
--- a/src/Text/Pandoc/Pretty.hs
+++ b/src/Text/Pandoc/Pretty.hs
@@ -65,7 +65,7 @@ import Control.Monad
import Control.Monad.State.Strict
import Data.Char (isSpace)
import Data.Foldable (toList)
-import Data.List (intersperse)
+import Data.List (intersperse, foldl')
import Data.Sequence (Seq, ViewL (..), fromList, mapWithIndex, singleton, viewl,
(<|))
import qualified Data.Sequence as Seq
@@ -305,7 +305,7 @@ renderList (BreakingSpace : xs) = do
let xs' = dropWhile isBreakingSpace xs
let next = takeWhile isText xs'
st <- get
- let off = sum $ map offsetOf next
+ let off = foldl' (+) 0 $ map offsetOf next
case lineLength st of
Just l | column st + 1 + off > l -> do
outp (-1) "\n"
@@ -540,4 +540,4 @@ charWidth c =
-- | Get real length of string, taking into account combining and double-wide
-- characters.
realLength :: String -> Int
-realLength = sum . map charWidth
+realLength = foldl' (+) 0 . map charWidth