Bug 1387400 - Part 1: Only call GetElemBaseForLambda for large strings. r=till
authorAndré Bargull <andre.bargull@gmail.com>
Wed, 09 Aug 2017 11:32:31 +0200
changeset 643353 b88c60c642491cb6b253db16563518fde41054ea
parent 643352 1f294885ea45176fa4e512584cf1052c00b3975f
child 643354 3167f8853dff972e8298f03fece5ca909fe8c69a
push id73068
push usergpascutto@mozilla.com
push dateWed, 09 Aug 2017 16:52:24 +0000
reviewerstill
bugs1387400
milestone57.0a1
Bug 1387400 - Part 1: Only call GetElemBaseForLambda for large strings. r=till
js/src/builtin/RegExp.js
--- a/js/src/builtin/RegExp.js
+++ b/js/src/builtin/RegExp.js
@@ -280,20 +280,24 @@ function RegExpReplace(string, replaceVa
         var global = !!(flags & REGEXP_GLOBAL_FLAG);
 
         // Steps 8-16.
         if (global) {
             // Step 8.a.
             var fullUnicode = !!(flags & REGEXP_UNICODE_FLAG);
 
             if (functionalReplace) {
-                var elemBase = GetElemBaseForLambda(replaceValue);
-                if (IsObject(elemBase)) {
-                    return RegExpGlobalReplaceOptElemBase(rx, S, lengthS, replaceValue,
-                                                          fullUnicode, elemBase);
+                // For large strings check if the replacer function is
+                // applicable for the elem-base optimization.
+                if (lengthS > 5000) {
+                    var elemBase = GetElemBaseForLambda(replaceValue);
+                    if (IsObject(elemBase)) {
+                        return RegExpGlobalReplaceOptElemBase(rx, S, lengthS, replaceValue,
+                                                              fullUnicode, elemBase);
+                    }
                 }
                 return RegExpGlobalReplaceOptFunc(rx, S, lengthS, replaceValue,
                                                   fullUnicode);
             }
             if (firstDollarIndex !== -1) {
                 return RegExpGlobalReplaceOptSubst(rx, S, lengthS, replaceValue,
                                                    fullUnicode, firstDollarIndex);
             }