From be733385c9457a006da2b5d92fed0077401c3d1c Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 11 Mar 2017 18:42:39 +0100 Subject: Markdown reader: optimized nonindentSpaces. Makes the benchmark go from 40 to 36 ms. --- src/Text/Pandoc/Readers/Markdown.hs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 2cd1c0d83..169872391 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -133,17 +133,14 @@ indentSpaces = try $ do nonindentSpaces :: PandocMonad m => MarkdownParser m String nonindentSpaces = do - tabStop <- getOption readerTabStop - sps <- many (char ' ') - if length sps < tabStop - then return sps - else unexpected "indented line" + n <- skipNonindentSpaces + return $ replicate n ' ' -- returns number of spaces parsed skipNonindentSpaces :: PandocMonad m => MarkdownParser m Int skipNonindentSpaces = do tabStop <- getOption readerTabStop - atMostSpaces (tabStop - 1) <* notFollowedBy (char ' ') + atMostSpaces (tabStop - 1) <* notFollowedBy spaceChar atMostSpaces :: PandocMonad m => Int -> MarkdownParser m Int atMostSpaces n -- cgit v1.2.3