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

Unified Diff: src/regexp.js

Issue 4517003: Special case global and non-global code paths in regexp.test. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 1 month 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/regexp.js
===================================================================
--- src/regexp.js (revision 5772)
+++ src/regexp.js (working copy)
@@ -193,20 +193,16 @@
var matchIndices = %_RegExpExec(this, s, i, lastMatchInfo);
if (matchIndices === null) {
- if (global) {
- this.lastIndex = 0;
- }
+ if (global) this.lastIndex = 0;
return null;
}
// Successful match.
lastMatchInfoOverride = null;
- var result = BuildResultFromMatchInfo(matchIndices, s);
-
if (global) {
this.lastIndex = lastMatchInfo[CAPTURE1];
}
- return result;
+ return BuildResultFromMatchInfo(matchIndices, s);
}
@@ -244,43 +240,44 @@
// algorithm, step 5) even if the value is discarded for non-global RegExps.
var i = TO_INTEGER(lastIndex);
- var global = this.global;
- if (global) {
+ if (this.global) {
if (i < 0 || i > s.length) {
this.lastIndex = 0;
return false;
}
+ %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, s, lastIndex]);
+ // matchIndices is either null or the lastMatchInfo array.
+ var matchIndices = %_RegExpExec(this, s, i, lastMatchInfo);
+ if (matchIndices === null) {
+ this.lastIndex = 0;
+ return false;
+ }
+ lastMatchInfoOverride = null;
+ this.lastIndex = lastMatchInfo[CAPTURE1];
+ return true;
} else {
- i = 0;
+ // Non-global regexp.
+ // Remove irrelevant preceeding '.*' in a non-global test regexp.
+ // The expression checks whether this.source starts with '.*' and
+ // that the third char is not a '?'.
+ if (%_StringCharCodeAt(this.source, 0) == 46 && // '.'
+ %_StringCharCodeAt(this.source, 1) == 42 && // '*'
+ %_StringCharCodeAt(this.source, 2) != 63) { // '?'
Lasse Reichstein 2010/11/05 14:01:30 Why not do this for global regexps too?
+ if (!%_ObjectEquals(regexp_key, this)) {
+ regexp_key = this;
+ regexp_val = new $RegExp(this.source.substring(2, this.source.length),
+ (this.ignoreCase ? 'i' : '')
+ + (this.multiline ? 'm' : ''));
+ }
+ if (!regexp_val.test(s)) return false;
+ }
+ %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, s, lastIndex]);
+ // matchIndices is either null or the lastMatchInfo array.
+ var matchIndices = %_RegExpExec(this, s, 0, lastMatchInfo);
+ if (matchIndices === null) return false;
+ lastMatchInfoOverride = null;
+ return true;
}
-
- // Remove irrelevant preceeding '.*' in a test regexp. The expression
- // checks whether this.source starts with '.*' and that the third
- // char is not a '?'
- if (%_StringCharCodeAt(this.source, 0) == 46 && // '.'
- %_StringCharCodeAt(this.source, 1) == 42 && // '*'
- %_StringCharCodeAt(this.source, 2) != 63) { // '?'
- if (!%_ObjectEquals(regexp_key, this)) {
- regexp_key = this;
- regexp_val = new $RegExp(this.source.substring(2, this.source.length),
- (global ? 'g' : '')
- + (this.ignoreCase ? 'i' : '')
- + (this.multiline ? 'm' : ''));
- }
- if (!regexp_val.test(s)) return false;
- }
-
- %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, s, lastIndex]);
- // matchIndices is either null or the lastMatchInfo array.
- var matchIndices = %_RegExpExec(this, s, i, lastMatchInfo);
-
- if (matchIndices === null) {
- if (global) this.lastIndex = 0;
- return false;
- }
- lastMatchInfoOverride = null;
- if (global) this.lastIndex = lastMatchInfo[CAPTURE1];
- return true;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698