aboutsummaryrefslogtreecommitdiff
path: root/js/lib
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-01-10 15:27:32 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-01-10 15:27:32 -0800
commitec18344cf02a03c0c3a2254c72b7efc2d378d71a (patch)
tree90fb81e36096a37a0ae9c1aa92b11e5e93688670 /js/lib
parent9ff768886050b8a62cba180d9c2d575c0fe82364 (diff)
Another "test before replace" optimization.
Diffstat (limited to 'js/lib')
-rw-r--r--js/lib/inlines.js8
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