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 |