Bug 1387400 - Part 1: Only call GetElemBaseForLambda for large strings. r=till
--- 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);
}