From ec18344cf02a03c0c3a2254c72b7efc2d378d71a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 10 Jan 2015 15:27:32 -0800 Subject: Another "test before replace" optimization. --- js/lib/inlines.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'js') diff --git a/js/lib/inlines.js b/js/lib/inlines.js index 0dc5e3c..4d49861 100644 --- a/js/lib/inlines.js +++ b/js/lib/inlines.js @@ -65,6 +65,8 @@ var reEntityHere = new RegExp('^' + ENTITY, 'i'); var reEntityOrEscapedChar = new RegExp('\\\\' + ESCAPABLE + '|' + ENTITY, 'gi'); +var reBackslashOrAmp = /[\\&]/; + var reTicks = new RegExp('`+'); var reTicksHere = new RegExp('^`+'); @@ -102,7 +104,11 @@ var unescapeChar = function(s) { // Replace entities and backslash escapes with literal characters. var unescapeString = function(s) { "use strict"; - return s.replace(reEntityOrEscapedChar, unescapeChar); + if (reBackslashOrAmp.test(s)) { + return s.replace(reEntityOrEscapedChar, unescapeChar); + } else { + return s; + } }; // Normalize reference label: collapse internal whitespace -- cgit v1.2.3