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

Unified Diff: src/string.js

Issue 3034060: Create a new RegExp object for every evaluation of a RegExp literal. (Closed)
Patch Set: Addressed review comments. Created 10 years, 4 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 | « src/runtime.cc ('k') | src/x64/codegen-x64.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/string.js
diff --git a/src/string.js b/src/string.js
index cc6504fef315aa382a003b6e0a6e42c568c02af8..30eedb3c9a2fe9451ccf08a5d0469ae91b3143d3 100644
--- a/src/string.js
+++ b/src/string.js
@@ -177,7 +177,7 @@ function StringMatch(regexp) {
var saveAnswer = false;
if (%_ObjectEquals(cache.type, 'match') &&
- %_ObjectEquals(cache.regExp, regexp) &&
+ %_IsRegExpEquivalent(cache.regExp, regexp) &&
%_ObjectEquals(cache.subject, subject)) {
if (cache.answerSaved) {
return CloneDenseArray(cache.answer);
@@ -274,8 +274,8 @@ function StringReplace(search, replace) {
// Helper function for regular expressions in String.prototype.replace.
function StringReplaceRegExp(subject, regexp, replace) {
var cache = regExpCache;
- if (%_ObjectEquals(cache.regExp, regexp) &&
- %_ObjectEquals(cache.type, 'replace') &&
+ if (%_ObjectEquals(cache.type, 'replace') &&
+ %_IsRegExpEquivalent(cache.regExp, regexp) &&
%_ObjectEquals(cache.replaceString, replace) &&
%_ObjectEquals(cache.subject, subject)) {
return cache.answer;
@@ -609,8 +609,9 @@ function StringSplit(separator, limit) {
var saveAnswer = false;
if (%_ObjectEquals(cache.type, 'split') &&
- %_ObjectEquals(cache.regExp, separator) &&
- %_ObjectEquals(cache.subject, subject)) {
+ %_IsRegExpEquivalent(cache.regExp, separator) &&
+ %_ObjectEquals(cache.subject, subject) &&
+ %_ObjectEquals(cache.lastIndex, limit)) {
if (cache.answerSaved) {
return CloneDenseArray(cache.answer);
} else {
@@ -621,6 +622,8 @@ function StringSplit(separator, limit) {
cache.type = 'split';
cache.regExp = separator;
cache.subject = subject;
+ // Reuse lastIndex field for split limit when type is "split".
+ cache.lastIndex = limit;
%_Log('regexp', 'regexp-split,%0S,%1r', [subject, separator]);
« no previous file with comments | « src/runtime.cc ('k') | src/x64/codegen-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698