OLD | NEW |
---|---|
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 ExpandReplacement(replace, subject, reusableMatchInfo, builder); | 232 ExpandReplacement(replace, subject, reusableMatchInfo, builder); |
233 } | 233 } |
234 | 234 |
235 // suffix | 235 // suffix |
236 builder.addSpecialSlice(end, subject.length); | 236 builder.addSpecialSlice(end, subject.length); |
237 | 237 |
238 return builder.generate(); | 238 return builder.generate(); |
239 } | 239 } |
240 | 240 |
241 | 241 |
242 var cachedReplaceSubject; | |
243 var cachedReplaceRegexp; | |
244 var cachedReplaceReplacement; | |
245 var cachedReplaceAnswer; | |
246 | |
242 // Helper function for regular expressions in String.prototype.replace. | 247 // Helper function for regular expressions in String.prototype.replace. |
243 function StringReplaceRegExp(subject, regexp, replace) { | 248 function StringReplaceRegExp(subject, regexp, replace) { |
249 if (replace === cachedReplaceReplacement && | |
250 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.
| |
251 regexp === cachedReplaceRegexp) { | |
252 return cachedReplaceAnswer; | |
253 } | |
244 replace = TO_STRING_INLINE(replace); | 254 replace = TO_STRING_INLINE(replace); |
245 return %StringReplaceRegExpWithString(subject, | 255 var answer = %StringReplaceRegExpWithString(subject, |
246 regexp, | 256 regexp, |
247 replace, | 257 replace, |
248 lastMatchInfo); | 258 lastMatchInfo); |
249 }; | 259 cachedReplaceSubject = subject; |
260 cachedReplaceRegexp = regexp; | |
261 cachedReplaceReplacement = replace; | |
262 cachedReplaceAnswer = answer; | |
263 return answer; | |
264 } | |
250 | 265 |
251 | 266 |
252 // Expand the $-expressions in the string and return a new string with | 267 // Expand the $-expressions in the string and return a new string with |
253 // the result. | 268 // the result. |
254 function ExpandReplacement(string, subject, matchInfo, builder) { | 269 function ExpandReplacement(string, subject, matchInfo, builder) { |
255 var next = %StringIndexOf(string, '$', 0); | 270 var next = %StringIndexOf(string, '$', 0); |
256 if (next < 0) { | 271 if (next < 0) { |
257 builder.add(string); | 272 builder.add(string); |
258 return; | 273 return; |
259 } | 274 } |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
900 "small", StringSmall, | 915 "small", StringSmall, |
901 "strike", StringStrike, | 916 "strike", StringStrike, |
902 "sub", StringSub, | 917 "sub", StringSub, |
903 "sup", StringSup, | 918 "sup", StringSup, |
904 "toJSON", StringToJSON | 919 "toJSON", StringToJSON |
905 )); | 920 )); |
906 } | 921 } |
907 | 922 |
908 | 923 |
909 SetupString(); | 924 SetupString(); |
OLD | NEW |