From 0e8c3fc0f2878ad45023dc53d1fbbc53b82b94d2 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 9 Jan 2015 21:46:06 -0800 Subject: Improved unescapeString performance. --- js/lib/inlines.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/js/lib/inlines.js b/js/lib/inlines.js index f27a7e7..405c6c9 100644 --- a/js/lib/inlines.js +++ b/js/lib/inlines.js @@ -68,14 +68,23 @@ var reEntityHere = new RegExp('^' + ENTITY, 'i'); var reEntity = new RegExp(ENTITY, 'gi'); +var reEntityOrEscapedChar = new RegExp('\\\\' + ESCAPABLE + '|' + ENTITY, 'gi'); + // Matches a string of non-special characters. var reMain = /^[^\n`\[\]\\!<&*_]+/m; +var unescapeChar = function(s) { + if (s[0] === '\\') { + return s[1]; + } else { + return entityToChar(s); + } +}; + // Replace entities and backslash escapes with literal characters. var unescapeString = function(s) { "use strict"; - return s.replace(reAllEscapedChar, '$1') - .replace(reEntity, entityToChar); + return s.replace(reEntityOrEscapedChar, unescapeChar); }; // Normalize reference label: collapse internal whitespace -- cgit v1.2.3