diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-01-25 15:32:10 -0800 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-01-25 15:32:10 -0800 |
commit | 4c74b7aaabe42428b8de9dade89e42c5cccc9463 (patch) | |
tree | ffa95cc18612d90dc74dc64270e1aa58c388633d /src/Text | |
parent | 0bc9b0679b6c565bc50ce56e16e3b4ed7a97783b (diff) | |
download | pandoc-4c74b7aaabe42428b8de9dade89e42c5cccc9463.tar.gz |
Parsing: Much faster new version of anyLine.
Not only faster but uses less memory.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Parsing.hs | 9 |
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 |