From 9fbeb5a6ecf3ea16d29ef54f25813f92b537203b Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Thu, 16 Oct 2014 23:31:50 +0400 Subject: [PATCH] Perf: escaping --- lib/rules_inline/escape.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/rules_inline/escape.js b/lib/rules_inline/escape.js index 81201f0..5c68a23 100644 --- a/lib/rules_inline/escape.js +++ b/lib/rules_inline/escape.js @@ -1,8 +1,9 @@ // Proceess escaped chars and hardbreaks -var ESCAPED = '\\!"#$%&\'()*+,./:;<=>?@[]^_`{|}~-' - .split('') - .map(function(ch) { return ch.charCodeAt(0); }); +var ESCAPED = {}; + +'\\!"#$%&\'()*+,./:;<=>?@[]^_`{|}~-' + .split('').forEach(function(ch) { ESCAPED[ch.charCodeAt(0)] = true; }); module.exports = function escape(state) { var ch, pos = state.pos, max = state.posMax; @@ -14,7 +15,7 @@ module.exports = function escape(state) { if (pos < max) { ch = state.src.charCodeAt(pos); - if (ESCAPED.indexOf(ch) >= 0) { + if (typeof ESCAPED[ch] !== 'undefined') { // escape html chars if needed if (ch === 0x26/* & */) { state.pending += '&';