diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2012-07-24 07:13:49 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2012-07-24 07:13:49 -0700 |
commit | ce72d6aba83981dee3deb012373bd11e7432142a (patch) | |
tree | 2cfed3f35c77dc0cee52e99c1b8df24f90dc0c71 /src | |
parent | fb6e7989170ac73e75f6ecdf79b8aaca5d353c76 (diff) |
Slight improvement to performance for pipe tables.
Still, pipe tables are a huge performance drag. One benchmark:
With pipe tables, 1.25 sec (including this fix).
without pipe tables, 1.05 sec.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 1786c7f45..8806416a7 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -913,17 +913,18 @@ pipeTable headless = tableWith (pipeTableHeader headless) -- | Parse header for an pipe table. pipeTableHeader :: Bool -- ^ Headerless table -> Parser [Char] ParserState ([[Block]], [Alignment], [Int]) -pipeTableHeader headless = try $ do - optional blanklines - heads <- if headless - then return $ repeat [] - else pipeTableRow - aligns <- nonindentSpaces >> optional (char '|') >> - pipeTableHeaderPart `sepBy1` sepPipe - optional (char '|') - newline - let cols = length aligns - return (take cols heads, aligns, []) +pipeTableHeader headless = do + scanForPipe + try $ do + heads <- if headless + then return $ repeat [] + else pipeTableRow + aligns <- nonindentSpaces >> optional (char '|') >> + pipeTableHeaderPart `sepBy1` sepPipe + optional (char '|') + newline + let cols = length aligns + return (take cols heads, aligns, []) sepPipe :: Parser [Char] ParserState () sepPipe = try $ char '|' >> notFollowedBy blankline @@ -955,6 +956,10 @@ pipeTableHeaderPart = do (Nothing,Just _) -> AlignRight (Just _,Just _) -> AlignCenter +-- Succeed only if current line contains a pipe. +scanForPipe :: Parser [Char] st () +scanForPipe = lookAhead (manyTill (satisfy (/='\n')) (char '|')) >> return () + table :: Parser [Char] ParserState Block table = multilineTable False <|> simpleTable True <|> simpleTable False <|> multilineTable True <|> |