From 7e6720ee4dbc409c72236c755fd4fbfe95d7d228 Mon Sep 17 00:00:00 2001 From: Zixaphir Date: Tue, 13 Jan 2015 10:29:34 -0700 Subject: [PATCH] Speed E the fuck up --- builds/appchan-x.user.js | 29 ++++++++++++++++++----------- builds/crx/script.js | 29 ++++++++++++++++++----------- src/General/Globals.coffee | 10 +++++++--- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/builds/appchan-x.user.js b/builds/appchan-x.user.js index c26490ed7..908afe4e1 100644 --- a/builds/appchan-x.user.js +++ b/builds/appchan-x.user.js @@ -508,17 +508,24 @@ boards: {} }; - E = function(text) { - return (text + '').replace(/[&"'<>]/g, function(x) { - return { - '&': '&', - "'": ''', - '"': '"', - '<': '<', - '>': '>' - }[x]; - }); - }; + E = (function() { + var fn, r, regex, str; + str = { + '&': '&', + "'": ''', + '"': '"', + '<': '<', + '>': '>' + }; + r = String.prototype.replace; + regex = /[&"'<>]/g; + fn = function(x) { + return str[x]; + }; + return function(text) { + return r.call(text, regex, fn); + }; + })(); Mascots = { 'Akiyama_Mio': { diff --git a/builds/crx/script.js b/builds/crx/script.js index 3980758b3..0cad5e719 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -480,17 +480,24 @@ boards: {} }; - E = function(text) { - return (text + '').replace(/[&"'<>]/g, function(x) { - return { - '&': '&', - "'": ''', - '"': '"', - '<': '<', - '>': '>' - }[x]; - }); - }; + E = (function() { + var fn, r, regex, str; + str = { + '&': '&', + "'": ''', + '"': '"', + '<': '<', + '>': '>' + }; + r = String.prototype.replace; + regex = /[&"'<>]/g; + fn = function(x) { + return str[x]; + }; + return function(text) { + return r.call(text, regex, fn); + }; + })(); Mascots = { 'Akiyama_Mio': { diff --git a/src/General/Globals.coffee b/src/General/Globals.coffee index c3d7656e3..7a1fc742e 100755 --- a/src/General/Globals.coffee +++ b/src/General/Globals.coffee @@ -14,6 +14,10 @@ g = CHANGELOG: '<%= meta.repo %>blob/<%= meta.mainBranch %>/CHANGELOG.md' boards: {} -E = (text) -> - (text+'').replace /[&"'<>]/g, (x) -> - {'&': '&', "'": ''', '"': '"', '<': '<', '>': '>'}[x] \ No newline at end of file +E = do -> + str = {'&': '&', "'": ''', '"': '"', '<': '<', '>': '>'} + r = String::replace + regex = /[&"'<>]/g + fn = (x) -> + str[x] + (text) -> r.call text, regex, fn \ No newline at end of file