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

Unified Diff: src/regexp.js

Issue 1556019: Avoid unnecessary cloning of regexp answer (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 8 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 | src/string.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/regexp.js
===================================================================
--- src/regexp.js (revision 4357)
+++ src/regexp.js (working copy)
@@ -126,6 +126,9 @@
this.replaceString = 0;
this.lastIndex = 0;
this.answer = 0;
+ // answerSaved marks whether the contents of answer is valid for a cache
+ // hit in RegExpExec, StringMatch and StringSplit.
+ this.answerSaved = false;
}
@@ -133,6 +136,7 @@
function CloneRegexpAnswer(array) {
+ if (array == null) return null;
var len = array.length;
var answer = new $Array(len);
for (var i = 0; i < len; i++) {
@@ -151,17 +155,19 @@
}
var cache = regExpCache;
+ var saveAnswer = false;
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;
+ if (cache.answerSaved) {
+ return CloneRegexpAnswer(cache.answer);
} else {
- return CloneRegexpAnswer(last);
+ saveAnswer = true;
}
+ } else {
+ cache.answerSaved = false;
Lasse Reichstein 2010/04/08 14:50:52 No need to set answerSaved here. Set it, unconditi
}
if (%_ArgumentsLength() == 0) {
@@ -196,6 +202,7 @@
cache.regExp = this;
cache.subject = s;
cache.answer = matchIndices; // Null.
+ cache.answerSaved = true; // Safe since no cloning is needed.
cache.type = 'exec';
return matchIndices; // No match.
}
@@ -225,15 +232,18 @@
result.input = s;
if (this.global) {
this.lastIndex = lastMatchInfo[CAPTURE1];
- return result;
} else {
cache.regExp = this;
cache.subject = s;
cache.lastIndex = lastIndex;
- cache.answer = result;
+ if (saveAnswer) {
+ cache.answer = CloneRegexpAnswer(result);
+ cache.answerSaved = true;
Lasse Reichstein 2010/04/08 14:50:52 I.e., always set answerSaved to saveAnswer here.
+ }
cache.type = 'exec';
- return CloneRegexpAnswer(result);
}
+ return result;
+
}
« no previous file with comments | « no previous file | src/string.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698