git.iko.soy/typeable/pandoc
on master help sign in
Parsing: Much faster new version of anyLine.

Not only faster but uses less memory.

commit4c74b7aaabe42428b8de9dade89e42c5cccc9463 authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 25 Jan 2013, 15:32 (14 years ago) parent0bc9b06
1 file changed+8−1
src/Text/Pandoc/Parsing.hs+8−1
src/Text/Pandoc/Parsing.hs+8−1
@@ -190,7 +190,14 @@ a >>~ b = a >>= \x -> b >> return x
190190
191191-- | Parse any line of text
192192anyLine :: Parser [Char] st [Char]
193−anyLine = manyTill anyChar newline
193+anyLine = do
194+ -- This is much faster than:
195+ -- manyTill anyChar newline
196+ inp <- getInput
197+ let (this, rest) = break (=='\n') inp
198+ setInput rest
199+ void (char '\n') <|> (guard (not $ null this) >> eof)
200+ return this
194201
195202-- | Like @manyTill@, but reads at least one item.
196203many1Till :: Parser [tok] st a