Chromium Code Reviews| 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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 var parameters = $Array(m + 2); | 514 var parameters = $Array(m + 2); |
| 515 for (var j = 0; j < m; j++) { | 515 for (var j = 0; j < m; j++) { |
| 516 parameters[j] = CaptureString(subject, matchInfo, j); | 516 parameters[j] = CaptureString(subject, matchInfo, j); |
| 517 } | 517 } |
| 518 parameters[j] = index; | 518 parameters[j] = index; |
| 519 parameters[j + 1] = subject; | 519 parameters[j + 1] = subject; |
| 520 return replace.apply(null, parameters); | 520 return replace.apply(null, parameters); |
| 521 } | 521 } |
| 522 | 522 |
| 523 | 523 |
| 524 var re_cache = {} | |
| 525 | |
| 526 | |
| 524 // ECMA-262 section 15.5.4.12 | 527 // ECMA-262 section 15.5.4.12 |
| 525 function StringSearch(re) { | 528 function StringSearch(re) { |
| 526 var regexp = new $RegExp(re); | 529 var regexp = re_cache[re]; |
| 530 if (IS_UNDEFINED(regexp)) { | |
|
sandholm
2010/03/25 05:36:24
Maybe reset cache at size 10, 100 or 1000 to avoid
| |
| 531 regexp = new $RegExp(re); | |
| 532 re_cache[re] = regexp; | |
| 533 } | |
| 527 var s = TO_STRING_INLINE(this); | 534 var s = TO_STRING_INLINE(this); |
| 528 var last_idx = regexp.lastIndex; // keep old lastIndex | 535 var last_idx = regexp.lastIndex; // keep old lastIndex |
|
Lasse Reichstein
2010/03/25 08:05:13
Use:
var match = DoRegExpExec(regexp, s, 0);
i
Lasse Reichstein
2010/03/25 08:53:11
I'll just make a changelist for this on its own.
| |
| 529 regexp.lastIndex = 0; // ignore re.global property | 536 regexp.lastIndex = 0; // ignore re.global property |
| 530 var result = regexp.exec(s); | 537 var result = regexp.exec(s); |
| 531 regexp.lastIndex = last_idx; // restore lastIndex | 538 regexp.lastIndex = last_idx; // restore lastIndex |
| 532 if (result == null) | 539 if (result == null) |
| 533 return -1; | 540 return -1; |
| 534 else | 541 else |
| 535 return result.index; | 542 return result.index; |
| 536 } | 543 } |
| 537 | 544 |
| 538 | 545 |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 986 "small", StringSmall, | 993 "small", StringSmall, |
| 987 "strike", StringStrike, | 994 "strike", StringStrike, |
| 988 "sub", StringSub, | 995 "sub", StringSub, |
| 989 "sup", StringSup, | 996 "sup", StringSup, |
| 990 "toJSON", StringToJSON | 997 "toJSON", StringToJSON |
| 991 )); | 998 )); |
| 992 } | 999 } |
| 993 | 1000 |
| 994 | 1001 |
| 995 SetupString(); | 1002 SetupString(); |
| OLD | NEW |