git.iko.soy/typeable/pandoc
on master help sign in
Changed Entities.hs to use Data.Map rather than

an association list, for a slight performance boost. git-svn-id: https://pandoc.googlecode.com/svn/trunk@532 788f1e2b-df1e-0410-8736-df70ead52e1b

commit1266b189a1d3dd771621eea0fb4917367e6cd04d authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateWed 14 Feb 2007, 17:39 (20 years ago) parent5a9b7c2
1 file changed+7−9
src/Text/Pandoc/Entities.hs+7−9
src/Text/Pandoc/Entities.hs+7−9
@@ -39,15 +39,15 @@ module Text.Pandoc.Entities (
3939import Data.Char ( chr, ord )
4040import Text.ParserCombinators.Parsec
4141import Data.Maybe ( fromMaybe )
42+import qualified Data.Map as Map
4243
4344-- | Returns a string containing an entity reference for the character.
4445charToEntity :: Char -> String
4546charToEntity char =
46− let matches = filter (\(entity, character) -> (character == char))
47− entityTable in
48− if (length matches) == 0
47+ let matches = Map.filter (== char) entityTable in
48+ if Map.null matches
4949 then charToNumericalEntity char
50− else fst (head matches)
50+ else head $ Map.keys matches
5151
5252-- | Returns a string containing a numerical entity reference for the char.
5353charToNumericalEntity :: Char -> String
@@ -64,9 +64,7 @@ namedEntity = try $ do
6464 body <- many1 alphaNum
6565 end <- char ';'
6666 let entity = "&" ++ body ++ ";"
67− return $ case (lookup entity entityTable) of
68− Just ch -> ch
69− Nothing -> '?'
67+ return $ Map.findWithDefault '?' entity entityTable
7068
7169-- | Parse SGML hexadecimal entity.
7270hexEntity :: GenParser Char st Char
@@ -114,8 +112,8 @@ decodeEntities str =
114112 Left err -> error $ "\nError: " ++ show err
115113 Right result -> result
116114
117−entityTable :: [(String, Char)]
118−entityTable = [
115+entityTable :: Map.Map String Char
116+entityTable = Map.fromList [
119117 ("&quot;", chr 34),
120118 ("&amp;", chr 38),
121119 ("&lt;", chr 60),