Bug 1263490 - Part 1: Do not search for dollar if the length of replaceValue is 0 or 1. r=till
authorTooru Fujisawa <arai_a@mac.com>
Thu, 21 Apr 2016 08:45:40 +0900
changeset 332064 4226c06dcf1ffa0d965bf6f8c77adf992a8b7d6b
parent 332063 0b609cab107795bd79520e1674ddfdee80e46a8a
child 332065 7f41c81e14d24e71d3ab0210b3cb518f42eb4f35
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstill
bugs1263490
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1263490 - Part 1: Do not search for dollar if the length of replaceValue is 0 or 1. r=till
js/src/builtin/RegExp.js
--- a/js/src/builtin/RegExp.js
+++ b/js/src/builtin/RegExp.js
@@ -180,17 +180,22 @@ function RegExpReplace(string, replaceVa
     // Step 5.
     var functionalReplace = IsCallable(replaceValue);
 
     // Step 6.
     var firstDollarIndex = -1;
     if (!functionalReplace) {
         // Step 6.a.
         replaceValue = ToString(replaceValue);
-        firstDollarIndex = callFunction(std_String_indexOf, replaceValue, "$");
+
+        // Skip if replaceValue is an empty string or a single character.
+        // A single character string may contain "$", but that cannot be a
+        // substitution.
+        if (replaceValue.length > 1)
+            firstDollarIndex = callFunction(std_String_indexOf, replaceValue, "$");
     }
 
     // Step 7.
     var global = !!rx.global;
 
     // Optimized paths for simple cases.
     if (!functionalReplace && firstDollarIndex === -1 && IsRegExpMethodOptimizable(rx)) {
         if (global) {