git.iko.soy/typeable/pandoc
on master help sign in
Parsing: More minor performance improvements.
0fa1023John MacFarlane
src/Text/Pandoc/Parsing.hs+13−10
@@ -190,7 +190,7 @@ where
190
190
191import Control.Monad.Identity
191import Control.Monad.Identity
192import Control.Monad.Reader
192import Control.Monad.Reader
193−import Data.Char (chr, isAlphaNum, isAscii, isAsciiUpper,
193+import Data.Char (chr, isAlphaNum, isAscii, isAsciiUpper, isAsciiLower,
194 isPunctuation, isSpace, ord, toLower, toUpper)
194 isPunctuation, isSpace, ord, toLower, toUpper)
195import Data.Default
195import Data.Default
196import Data.Functor (($>))
196import Data.Functor (($>))
@@ -444,12 +444,13 @@ spaceChar = satisfy $ \c -> c == ' ' || c == '\t'
444-- | Parses a nonspace, nonnewline character.
444-- | Parses a nonspace, nonnewline character.
445nonspaceChar :: Stream s m Char => ParserT s st m Char
445nonspaceChar :: Stream s m Char => ParserT s st m Char
446nonspaceChar = satisfy (not . isSpaceChar)
446nonspaceChar = satisfy (not . isSpaceChar)
447− where
447+
448+isSpaceChar :: Char -> Bool
448− isSpaceChar ' ' = True
449+isSpaceChar ' ' = True
449− isSpaceChar '\t' = True
450+isSpaceChar '\t' = True
450− isSpaceChar '\n' = True
451+isSpaceChar '\n' = True
451− isSpaceChar '\r' = True
452+isSpaceChar '\r' = True
452− isSpaceChar _ = False
453+isSpaceChar _ = False
453
454
454-- | Skips zero or more spaces or tabs.
455-- | Skips zero or more spaces or tabs.
455skipSpaces :: Stream s m Char => ParserT s st m ()
456skipSpaces :: Stream s m Char => ParserT s st m ()
@@ -682,7 +683,9 @@ mathInlineWith :: Stream s m Char => Text -> Text -> ParserT s st m Text
682mathInlineWith op cl = try $ do
683mathInlineWith op cl = try $ do
683 textStr op
684 textStr op
684 when (op == "$") $ notFollowedBy space
685 when (op == "$") $ notFollowedBy space
685− words' <- many1Till (countChar 1 (noneOf " \t\n\\")
686+ words' <- many1Till (
687+ (T.singleton <$>
688+ satisfy (\c -> not (isSpaceChar c || c == '\\')))
686 <|> (char '\\' >>
689 <|> (char '\\' >>
687 -- This next clause is needed because \text{..} can
690 -- This next clause is needed because \text{..} can
688 -- contain $, \(\), etc.
691 -- contain $, \(\), etc.
@@ -840,13 +843,13 @@ defaultNum = do
840-- | Parses a lowercase letter and returns (LowerAlpha, number).
843-- | Parses a lowercase letter and returns (LowerAlpha, number).
841lowerAlpha :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
844lowerAlpha :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
842lowerAlpha = do
845lowerAlpha = do
843− ch <- oneOf ['a'..'z']
846+ ch <- satisfy isAsciiLower
844 return (LowerAlpha, ord ch - ord 'a' + 1)
847 return (LowerAlpha, ord ch - ord 'a' + 1)
845
848
846-- | Parses an uppercase letter and returns (UpperAlpha, number).
849-- | Parses an uppercase letter and returns (UpperAlpha, number).
847upperAlpha :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
850upperAlpha :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
848upperAlpha = do
851upperAlpha = do
849− ch <- oneOf ['A'..'Z']
852+ ch <- satisfy isAsciiUpper
850 return (UpperAlpha, ord ch - ord 'A' + 1)
853 return (UpperAlpha, ord ch - ord 'A' + 1)
851
854
852-- | Parses a roman numeral i or I
855-- | Parses a roman numeral i or I