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

Unified Diff: src/string.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
« src/regexp.js ('K') | « src/regexp.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/string.js
===================================================================
--- src/string.js (revision 4357)
+++ src/string.js (working copy)
@@ -170,15 +170,15 @@
if (!regexp.global) return regexp.exec(subject);
var cache = regExpCache;
+ var saveAnswer = false;
if (%_ObjectEquals(cache.type, 'match') &&
%_ObjectEquals(cache.regExp, regexp) &&
%_ObjectEquals(cache.subject, subject)) {
- var last = cache.answer;
- if (last == null) {
- return last;
+ if (cache.answerSaved) {
+ return CloneRegexpAnswer(cache.answer);
} else {
- return CloneRegexpAnswer(last);
+ saveAnswer = true;
}
}
@@ -188,12 +188,9 @@
cache.type = 'match';
cache.regExp = regexp;
cache.subject = subject;
- cache.answer = result;
- if (result == null) {
- return result;
- } else {
- return CloneRegexpAnswer(result);
- }
+ if (saveAnswer) cache.answer = CloneRegexpAnswer(result);
+ cache.answerSaved = saveAnswer;
+ return result;
}
@@ -596,11 +593,16 @@
}
var cache = regExpCache;
+ var saveAnswer = false;
if (%_ObjectEquals(cache.type, 'split') &&
%_ObjectEquals(cache.regExp, separator) &&
%_ObjectEquals(cache.subject, subject)) {
- return CloneRegexpAnswer(cache.answer);
+ if (cache.answerSaved) {
+ return CloneRegexpAnswer(cache.answer);
+ } else {
+ saveAnswer = true;
+ }
}
cache.type = 'split';
@@ -610,6 +612,7 @@
%_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]);
if (length === 0) {
+ cache.answerSaved = true;
if (splitMatch(separator, subject, 0, 0) != null) {
cache.answer = [];
return [];
@@ -622,20 +625,19 @@
var startIndex = 0;
var result = [];
+ outer_loop:
while (true) {
if (startIndex === length) {
result[result.length] = subject.slice(currentIndex, length);
- cache.answer = result;
- return CloneRegexpAnswer(result);
+ break;
}
var matchInfo = splitMatch(separator, subject, currentIndex, startIndex);
if (IS_NULL(matchInfo)) {
result[result.length] = subject.slice(currentIndex, length);
- cache.answer = result;
- return CloneRegexpAnswer(result);
+ break;
}
var endIndex = matchInfo[CAPTURE1];
@@ -647,10 +649,7 @@
}
result[result.length] = SubString(subject, currentIndex, matchInfo[CAPTURE0]);
- if (result.length === limit) {
- cache.answer = result;
- return CloneRegexpAnswer(result);
- }
+ if (result.length === limit) break;
var num_captures = NUMBER_OF_CAPTURES(matchInfo);
for (var i = 2; i < num_captures; i += 2) {
@@ -661,14 +660,15 @@
} else {
result[result.length] = void 0;
}
- if (result.length === limit) {
- cache.answer = result;
- return CloneRegexpAnswer(result);
- }
+ if (result.length === limit) break outer_loop;
}
startIndex = currentIndex = endIndex;
}
+ if (saveAnswer) cache.answer = CloneRegexpAnswer(result);
+ cache.answerSaved = saveAnswer;
+ return result;
+
}
« src/regexp.js ('K') | « src/regexp.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698