Browse Source

Perf: escaping

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
9fbeb5a6ec
  1. 9
      lib/rules_inline/escape.js

9
lib/rules_inline/escape.js

@ -1,8 +1,9 @@
// Proceess escaped chars and hardbreaks // Proceess escaped chars and hardbreaks
var ESCAPED = '\\!"#$%&\'()*+,./:;<=>?@[]^_`{|}~-' var ESCAPED = {};
.split('')
.map(function(ch) { return ch.charCodeAt(0); }); '\\!"#$%&\'()*+,./:;<=>?@[]^_`{|}~-'
.split('').forEach(function(ch) { ESCAPED[ch.charCodeAt(0)] = true; });
module.exports = function escape(state) { module.exports = function escape(state) {
var ch, pos = state.pos, max = state.posMax; var ch, pos = state.pos, max = state.posMax;
@ -14,7 +15,7 @@ module.exports = function escape(state) {
if (pos < max) { if (pos < max) {
ch = state.src.charCodeAt(pos); ch = state.src.charCodeAt(pos);
if (ESCAPED.indexOf(ch) >= 0) { if (typeof ESCAPED[ch] !== 'undefined') {
// escape html chars if needed // escape html chars if needed
if (ch === 0x26/* & */) { if (ch === 0x26/* & */) {
state.pending += '&amp;'; state.pending += '&amp;';

Loading…
Cancel
Save