diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-02-14 18:02:51 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-02-14 18:02:51 +0000 |
commit | 0114f68d21b99a5bd1a96225e74440f05da2ce1c (patch) | |
tree | 40c877431b2452be2abaae8f59271eb8fd938c9f | |
parent | 1266b189a1d3dd771621eea0fb4917367e6cd04d (diff) | |
download | pandoc-0114f68d21b99a5bd1a96225e74440f05da2ce1c.tar.gz |
Introduced a new map, reverseEntityTable, for lookups
of entity by character, in Entities.hs. This yields a
small performance improvement.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@534 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r-- | src/Text/Pandoc/Entities.hs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Entities.hs b/src/Text/Pandoc/Entities.hs index 8e184432b..0b77ea334 100644 --- a/src/Text/Pandoc/Entities.hs +++ b/src/Text/Pandoc/Entities.hs @@ -43,11 +43,7 @@ import qualified Data.Map as Map -- | Returns a string containing an entity reference for the character. charToEntity :: Char -> String -charToEntity char = - let matches = Map.filter (== char) entityTable in - if Map.null matches - then charToNumericalEntity char - else head $ Map.keys matches +charToEntity char = Map.findWithDefault (charToNumericalEntity char) char reverseEntityTable -- | Returns a string containing a numerical entity reference for the char. charToNumericalEntity :: Char -> String @@ -113,7 +109,13 @@ decodeEntities str = Right result -> result entityTable :: Map.Map String Char -entityTable = Map.fromList [ +entityTable = Map.fromList entityTableList + +reverseEntityTable :: Map.Map Char String +reverseEntityTable = Map.fromList $ map (\(a,b) -> (b,a)) entityTableList + +entityTableList :: [(String, Char)] +entityTableList = [ (""", chr 34), ("&", chr 38), ("<", chr 60), |