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

Unified Diff: src/regexp.js

Issue 1148007: Merge bleeding_edge from version 2.1.3 up to revision 4205... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 years, 9 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
Index: src/regexp.js
===================================================================
--- src/regexp.js (revision 4205)
+++ src/regexp.js (working copy)
@@ -95,6 +95,7 @@
%IgnoreAttributesAndSetProperty(object, 'ignoreCase', ignoreCase);
%IgnoreAttributesAndSetProperty(object, 'multiline', multiline);
%IgnoreAttributesAndSetProperty(object, 'lastIndex', 0);
+ regExpCache.type = 'none';
}
// Call internal function to compile the pattern.
@@ -140,11 +141,51 @@
}
+function RegExpCache() {
+ this.type = 'none';
+ this.regExp = 0;
+ this.subject = 0;
+ this.replaceString = 0;
+ this.lastIndex = 0;
+ this.answer = 0;
+}
+
+
+var regExpCache = new RegExpCache();
+
+
+function CloneRegexpAnswer(array) {
+ var len = array.length;
+ var answer = new $Array(len);
+ for (var i = 0; i < len; i++) {
+ answer[i] = array[i];
+ }
+ answer.index = array.index;
+ answer.input = array.input;
+ return answer;
+}
+
+
function RegExpExec(string) {
if (!IS_REGEXP(this)) {
throw MakeTypeError('incompatible_method_receiver',
['RegExp.prototype.exec', this]);
}
+
+ var cache = regExpCache;
+
+ if (%_ObjectEquals(cache.type, 'exec') &&
+ %_ObjectEquals(cache.lastIndex, this.lastIndex) &&
+ %_ObjectEquals(cache.regExp, this) &&
+ %_ObjectEquals(cache.subject, string)) {
+ var last = cache.answer;
+ if (last == null) {
+ return last;
+ } else {
+ return CloneRegexpAnswer(last);
+ }
+ }
+
if (%_ArgumentsLength() == 0) {
var regExpInput = LAST_INPUT(lastMatchInfo);
if (IS_UNDEFINED(regExpInput)) {
@@ -159,6 +200,7 @@
s = ToString(string);
}
var lastIndex = this.lastIndex;
+
var i = this.global ? TO_INTEGER(lastIndex) : 0;
if (i < 0 || i > s.length) {
@@ -172,7 +214,12 @@
if (matchIndices == null) {
if (this.global) this.lastIndex = 0;
- return matchIndices; // no match
+ cache.lastIndex = lastIndex;
+ cache.regExp = this;
+ cache.subject = s;
+ cache.answer = matchIndices; // Null.
+ cache.type = 'exec';
+ return matchIndices; // No match.
}
var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1;
@@ -196,11 +243,19 @@
}
}
- if (this.global)
- this.lastIndex = lastMatchInfo[CAPTURE1];
result.index = lastMatchInfo[CAPTURE0];
result.input = s;
- return result;
+ if (this.global) {
+ this.lastIndex = lastMatchInfo[CAPTURE1];
+ return result;
+ } else {
+ cache.regExp = this;
+ cache.subject = s;
+ cache.lastIndex = lastIndex;
+ cache.answer = result;
+ cache.type = 'exec';
+ return CloneRegexpAnswer(result);
+ }
}
@@ -220,13 +275,35 @@
}
string = regExpInput;
}
- var s = ToString(string);
+ var s;
+ if (IS_STRING(string)) {
+ s = string;
+ } else {
+ s = ToString(string);
+ }
+
+ var lastIndex = this.lastIndex;
+
+ var cache = regExpCache;
+
+ if (%_ObjectEquals(cache.type, 'test') &&
+ %_ObjectEquals(cache.regExp, this) &&
+ %_ObjectEquals(cache.subject, string) &&
+ %_ObjectEquals(cache.lastIndex, lastIndex)) {
+ return cache.answer;
+ }
+
var length = s.length;
- var lastIndex = this.lastIndex;
var i = this.global ? TO_INTEGER(lastIndex) : 0;
+ cache.type = 'test';
+ cache.regExp = this;
+ cache.subject = s;
+ cache.lastIndex = i;
+
if (i < 0 || i > s.length) {
this.lastIndex = 0;
+ cache.answer = false;
return false;
}
@@ -236,10 +313,12 @@
if (matchIndices == null) {
if (this.global) this.lastIndex = 0;
+ cache.answer = false;
return false;
}
if (this.global) this.lastIndex = lastMatchInfo[CAPTURE1];
+ cache.answer = true;
return true;
}
@@ -358,6 +437,7 @@
return IS_UNDEFINED(regExpInput) ? "" : regExpInput;
}
function RegExpSetInput(string) {
+ regExpCache.type = 'none';
LAST_INPUT(lastMatchInfo) = ToString(string);
};

Powered by Google App Engine
This is Rietveld 408576698