git.iko.soy/typeable/pandoc
on master help sign in
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.

commitce72d6aba83981dee3deb012373bd11e7432142a authorJohn MacFarlane <fiddlosopher@gmail.com> dateTue 24 Jul 2012, 07:13 (14 years ago) parentfb6e798
1 file changed+16−11
src/Text/Pandoc/Readers/Markdown.hs+16−11
src/Text/Pandoc/Readers/Markdown.hs+16−11
@@ -913,17 +913,18 @@ pipeTable headless = tableWith (pipeTableHeader headless)
913913-- | Parse header for an pipe table.
914914pipeTableHeader :: Bool -- ^ Headerless table
915915 -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
916−pipeTableHeader headless = try $ do
917− optional blanklines
918− heads <- if headless
919− then return $ repeat []
920− else pipeTableRow
921− aligns <- nonindentSpaces >> optional (char '|') >>
922− pipeTableHeaderPart `sepBy1` sepPipe
923− optional (char '|')
924− newline
925− let cols = length aligns
926− return (take cols heads, aligns, [])
916+pipeTableHeader headless = do
917+ scanForPipe
918+ try $ do
919+ heads <- if headless
920+ then return $ repeat []
921+ else pipeTableRow
922+ aligns <- nonindentSpaces >> optional (char '|') >>
923+ pipeTableHeaderPart `sepBy1` sepPipe
924+ optional (char '|')
925+ newline
926+ let cols = length aligns
927+ return (take cols heads, aligns, [])
927928
928929sepPipe :: Parser [Char] ParserState ()
929930sepPipe = try $ char '|' >> notFollowedBy blankline
@@ -955,6 +956,10 @@ pipeTableHeaderPart = do
955956 (Nothing,Just _) -> AlignRight
956957 (Just _,Just _) -> AlignCenter
957958
959+-- Succeed only if current line contains a pipe.
960+scanForPipe :: Parser [Char] st ()
961+scanForPipe = lookAhead (manyTill (satisfy (/='\n')) (char '|')) >> return ()
962+
958963table :: Parser [Char] ParserState Block
959964table = multilineTable False <|> simpleTable True <|>
960965 simpleTable False <|> multilineTable True <|>