From e203c562d6f41e1d090e3470469d6b84069bc6da Mon Sep 17 00:00:00 2001
From: fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>
Date: Wed, 29 Apr 2009 19:28:39 +0000
Subject: [PATCH] Improved efficiency of whitespace parser.

git-svn-id: https://pandoc.googlecode.com/svn/trunk@1565 788f1e2b-df1e-0410-8736-df70ead52e1b
---
 src/Text/Pandoc/Readers/Markdown.hs | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 38a600abe..be9c4cfd5 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -55,9 +55,6 @@ readMarkdown state s = (readWith parseMarkdown) state (s ++ "\n\n")
 -- Constants and data structure definitions
 --
 
-spaceChars :: [Char]
-spaceChars = " \t"
-
 bulletListMarkers :: [Char]
 bulletListMarkers = "*+-"
 
@@ -325,7 +322,7 @@ hrule = try $ do
   skipSpaces
   start <- oneOf hruleChars
   count 2 (skipSpaces >> char start)
-  skipMany (oneOf spaceChars <|> char start)
+  skipMany (spaceChar <|> char start)
   newline
   optional blanklines
   return HorizontalRule
@@ -634,7 +631,7 @@ htmlBlock :: GenParser Char ParserState Block
 htmlBlock = try $ do
     failUnlessBeginningOfLine
     first <- htmlElement
-    finalSpace <- many (oneOf spaceChars)
+    finalSpace <- many spaceChar
     finalNewlines <- many newline
     return $ RawHtml $ first ++ finalSpace ++ finalNewlines
 
@@ -939,12 +936,12 @@ strikeout = failIfStrict >> enclosed (string "~~") (try $ string "~~") inline >>
 
 superscript :: GenParser Char ParserState Inline
 superscript = failIfStrict >> enclosed (char '^') (char '^') 
-              (notFollowedBy' whitespace >> inline) >>= -- may not contain Space
+              (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
               return . Superscript
 
 subscript :: GenParser Char ParserState Inline
 subscript = failIfStrict >> enclosed (char '~') (char '~')
-            (notFollowedBy' whitespace >> inline) >>=  -- may not contain Space
+            (notFollowedBy spaceChar >> inline) >>=  -- may not contain Space
             return . Subscript 
 
 abbrev :: GenParser Char ParserState Inline
@@ -1053,17 +1050,15 @@ emDash :: GenParser Char st Inline
 emDash = oneOfStrings ["---", "--"] >> return EmDash
 
 whitespace :: GenParser Char ParserState Inline
-whitespace = do
-  sps <- many1 (oneOf spaceChars)
-  if length sps >= 2
-     then option Space (endline >> return LineBreak)
-     else return Space <?> "whitespace"
+whitespace = spaceChar >>
+  (   (spaceChar >> skipMany spaceChar >> option Space (endline >> return LineBreak))
+  <|> (skipMany spaceChar >> return Space) ) <?> "whitespace"
 
 nonEndline :: GenParser Char st Char
 nonEndline = satisfy (/='\n')
 
 strChar :: GenParser Char st Char
-strChar = noneOf (specialChars ++ spaceChars ++ "\n")
+strChar = noneOf (specialChars ++ " \t\n")
 
 str :: GenParser Char st Inline
 str = many1 strChar >>= return . Str