git.iko.soy/typeable/pandoc
on master help sign in
XML: Replaced escapeStringAsXML with a faster version.

Benchmarked with criterion, it's about 8x faster than the old version. This speeds up docbook, opendocument, and html writers.

commit4e446358d1a356ba77c5f7b3cd967bf6c5285c15 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 21 Dec 2010, 08:22 (16 years ago) parent6aa0a18
1 file changed+1−9
src/Text/Pandoc/XML.hs+1−9
src/Text/Pandoc/XML.hs+1−9
@@ -55,17 +55,9 @@ escapeCharForXML x = case x of
5555 '"' -> "&quot;"
5656 c -> [c]
5757
58−-- | True if the character needs to be escaped.
59−needsEscaping :: Char -> Bool
60−needsEscaping c = c `elem` "&<>\""
61−
6258-- | Escape string as needed for XML. Entity references are not preserved.
6359escapeStringForXML :: String -> String
64−escapeStringForXML "" = ""
65−escapeStringForXML str =
66− case break needsEscaping str of
67− (okay, "") -> okay
68− (okay, (c:cs)) -> okay ++ escapeCharForXML c ++ escapeStringForXML cs
60+escapeStringForXML = concatMap escapeCharForXML
6961
7062-- | Return a text object with a string of formatted XML attributes.
7163attributeList :: [(String, String)] -> Doc