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

Unified Diff: src/string.js

Issue 817001: Add 1-element caches to RegExp.exec and String.replace. We... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
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
« src/regexp-delay.js ('K') | « src/regexp-delay.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 4060)
+++ src/string.js (working copy)
@@ -239,14 +239,29 @@
}
+var cachedReplaceSubject;
+var cachedReplaceRegexp;
+var cachedReplaceReplacement;
+var cachedReplaceAnswer;
+
// Helper function for regular expressions in String.prototype.replace.
function StringReplaceRegExp(subject, regexp, replace) {
+ if (replace === cachedReplaceReplacement &&
+ subject === cachedReplaceSubject &&
Mads Ager (chromium) 2010/03/10 08:12:22 %_ObjectEquals for these?
Lasse Reichstein 2010/03/10 08:53:24 Test FixedArray of subject.
+ regexp === cachedReplaceRegexp) {
+ return cachedReplaceAnswer;
+ }
replace = TO_STRING_INLINE(replace);
- return %StringReplaceRegExpWithString(subject,
- regexp,
- replace,
- lastMatchInfo);
-};
+ var answer = %StringReplaceRegExpWithString(subject,
+ regexp,
+ replace,
+ lastMatchInfo);
+ cachedReplaceSubject = subject;
+ cachedReplaceRegexp = regexp;
+ cachedReplaceReplacement = replace;
+ cachedReplaceAnswer = answer;
+ return answer;
+}
// Expand the $-expressions in the string and return a new string with
« src/regexp-delay.js ('K') | « src/regexp-delay.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698