diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-01-10 15:27:32 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-01-10 15:27:32 -0800 |
commit | ec18344cf02a03c0c3a2254c72b7efc2d378d71a (patch) | |
tree | 90fb81e36096a37a0ae9c1aa92b11e5e93688670 /js | |
parent | 9ff768886050b8a62cba180d9c2d575c0fe82364 (diff) |
Another "test before replace" optimization.
Diffstat (limited to 'js')
-rw-r--r-- | js/lib/inlines.js | 8 |
1 files changed, 7 insertions, 1 deletions
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 |