Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: src/js/regexp.js

Issue 2339443002: [regexp] Avoid unneeded accesses to lastIndex (Closed)
Patch Set: Update test262 status Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/regexp.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/regexp.js
diff --git a/src/js/regexp.js b/src/js/regexp.js
index f4101556b21dca293fd3c2c87a113bf1f6e4de99..66513b678dd17bdc2b45111a6af16617691cd5dd 100644
--- a/src/js/regexp.js
+++ b/src/js/regexp.js
@@ -185,29 +185,26 @@ function RegExpSubclassExecJS(string) {
}
string = TO_STRING(string);
- var lastIndex = this.lastIndex;
-
- // Conversion is required by the ES2015 specification (RegExpBuiltinExec
- // algorithm, step 4) even if the value is discarded for non-global RegExps.
- var i = TO_LENGTH(lastIndex);
+ var lastIndex;
var global = TO_BOOLEAN(REGEXP_GLOBAL(this));
var sticky = TO_BOOLEAN(REGEXP_STICKY(this));
var updateLastIndex = global || sticky;
if (updateLastIndex) {
- if (i > string.length) {
+ lastIndex = TO_LENGTH(this.lastIndex);
+ if (lastIndex > string.length) {
this.lastIndex = 0;
return null;
}
} else {
- i = 0;
+ lastIndex = 0;
}
// matchIndices is either null or the RegExpLastMatchInfo array.
- var matchIndices = %_RegExpExec(this, string, i, RegExpLastMatchInfo);
+ var matchIndices = %_RegExpExec(this, string, lastIndex, RegExpLastMatchInfo);
if (IS_NULL(matchIndices)) {
- this.lastIndex = 0;
+ if (updateLastIndex) this.lastIndex = 0;
return null;
}
@@ -935,9 +932,10 @@ function RegExpSubclassSearch(string) {
}
string = TO_STRING(string);
var previousLastIndex = this.lastIndex;
- this.lastIndex = 0;
+ if (previousLastIndex != 0) this.lastIndex = 0;
var result = RegExpSubclassExec(this, string);
- this.lastIndex = previousLastIndex;
+ var currentLastIndex = this.lastIndex;
+ if (currentLastIndex != previousLastIndex) this.lastIndex = previousLastIndex;
if (IS_NULL(result)) return -1;
return result.index;
}
« no previous file with comments | « no previous file | test/mjsunit/regexp.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698