From dbaac5e7244a04aa311a10632422b1546c02bae8 Mon Sep 17 00:00:00 2001 From: Daniel Morrison Date: Sun, 16 Nov 2014 00:28:21 -0500 Subject: [PATCH] Faster html_escape MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - uses string specific speedups - requires & be handled first - 33.7% overall speedup… we need this --- entei.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/entei.py b/entei.py index d1bafe3..c53716f 100755 --- a/entei.py +++ b/entei.py @@ -207,16 +207,16 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache', 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 '' -- 2.47.3