summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-01-25 15:32:10 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-01-25 15:32:10 -0800
commit4c74b7aaabe42428b8de9dade89e42c5cccc9463 (patch)
treeffa95cc18612d90dc74dc64270e1aa58c388633d
parent0bc9b0679b6c565bc50ce56e16e3b4ed7a97783b (diff)
Parsing: Much faster new version of anyLine.
Not only faster but uses less memory.
-rw-r--r--src/Text/Pandoc/Parsing.hs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index 2a5780f8f..7a3c5f27b 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -190,7 +190,14 @@ a >>~ b = a >>= \x -> b >> return x
-- | Parse any line of text
anyLine :: Parser [Char] st [Char]
-anyLine = manyTill anyChar newline
+anyLine = do
+ -- This is much faster than:
+ -- manyTill anyChar newline
+ inp <- getInput
+ let (this, rest) = break (=='\n') inp
+ setInput rest
+ void (char '\n') <|> (guard (not $ null this) >> eof)
+ return this
-- | Like @manyTill@, but reads at least one item.
many1Till :: Parser [tok] st a