git.iko.soy/typeable/pandoc
on master help sign in
Textile reader: Improved speed of hyphenedWords.

This speeds up the textile reader by about a factor of 4. But the reader is still very slow, compared to others readers.

commit37c29bfa3d3dda3cb4a59a3026c28c9cf202daba authorJohn MacFarlane <jgm@berkeley.edu> dateThu 6 Sep 2012, 13:49 (14 years ago) parentc2b520f
2 files changed+7−5
Makefile+1−1 src/Text/Pandoc/Readers/Textile.hs+6−4
Makefile+1−1
@@ -7,7 +7,7 @@ all:
77 cabal-dev configure --enable-tests --enable-benchmarks && cabal-dev build
88
99prof:
10− cabal-dev configure --enable-library-profiling --enable-executable-profiling && cabal-dev build
10+ cabal-dev configure --enable-tests --enable-library-profiling --enable-executable-profiling && cabal-dev build
1111
1212prep: pandoc-types citeproc-hs
1313 cabal-dev install-deps --enable-library-profiling --enable-tests --enable-benchmarks
src/Text/Pandoc/Readers/Textile.hs+6−4
@@ -61,6 +61,7 @@ import Text.Pandoc.Parsing
6161import Text.Pandoc.Readers.HTML ( htmlTag, isInlineTag, isBlockTag )
6262import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
6363import Text.HTML.TagSoup.Match
64+import Data.List ( intercalate )
6465import Data.Char ( digitToInt, isUpper )
6566import Control.Monad ( guard, liftM )
6667import Control.Applicative ((<$>), (*>), (<*))
@@ -426,14 +427,15 @@ wordBoundaries = markupChars ++ stringBreakers
426427
427428-- | Parse a hyphened sequence of words
428429hyphenedWords :: Parser [Char] ParserState String
429−hyphenedWords = try $ do
430+hyphenedWords = intercalate "-" <$> sepBy1 wordChunk (char '-')
431+
432+wordChunk :: Parser [Char] ParserState String
433+wordChunk = try $ do
430434 hd <- noneOf wordBoundaries
431435 tl <- many ( (noneOf wordBoundaries) <|>
432436 try (notFollowedBy' note *> oneOf markupChars
433437 <* lookAhead (noneOf wordBoundaries) ) )
434− let wd = hd:tl
435− option wd $ try $
436− (\r -> concat [wd, "-", r]) <$> (char '-' *> hyphenedWords)
438+ return $ hd:tl
437439
438440-- | Any string
439441str :: Parser [Char] ParserState Inline