From 4c74b7aaabe42428b8de9dade89e42c5cccc9463 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 25 Jan 2013 15:32:10 -0800 Subject: Parsing: Much faster new version of anyLine. Not only faster but uses less memory. --- src/Text/Pandoc/Parsing.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/Text') 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 -- cgit v1.2.3