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

Unified Diff: src/string.js

Issue 1207004: Cache regular expressions used in String.search. (Closed)
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
« no previous file with comments | « no previous file | no next file » | 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 e663ec304432f00b71c88765ac4858597e029156..1c72f3bc478d9a04ea3aa2f274efce5c0a2dfa01 100644
--- a/src/string.js
+++ b/src/string.js
@@ -521,9 +521,16 @@ function ApplyReplacementFunction(replace, matchInfo, subject) {
}
+var re_cache = {}
+
+
// ECMA-262 section 15.5.4.12
function StringSearch(re) {
- var regexp = new $RegExp(re);
+ var regexp = re_cache[re];
+ if (IS_UNDEFINED(regexp)) {
sandholm 2010/03/25 05:36:24 Maybe reset cache at size 10, 100 or 1000 to avoid
+ regexp = new $RegExp(re);
+ re_cache[re] = regexp;
+ }
var s = TO_STRING_INLINE(this);
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.
regexp.lastIndex = 0; // ignore re.global property
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698