- uses string specific speedups
- requires & be handled first
- 33.7% overall speedup… we need this
html_codes = {
'"': '"',
- '&': '&',
'<': '<',
'>': '>',
}
- def escape_char(char):
- return html_codes.get(char, char)
-
try:
- return ''.join(map(escape_char, string))
+ # & must be handled first
+ string = string.replace('&', '&')
+ for char in html_codes:
+ string = string.replace(char, html_codes[char])
+ return string
except TypeError:
return ''