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

Unified Diff: src/string.js

Issue 1223006: Change StringSearch to not call exec and build unnecessary intermediate array. (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..ca438fdde54155d967b77af501ed0724dbdb7b48 100644
--- a/src/string.js
+++ b/src/string.js
@@ -522,17 +522,15 @@ function ApplyReplacementFunction(replace, matchInfo, subject) {
// ECMA-262 section 15.5.4.12
-function StringSearch(re) {
+function StringSearch(re) {
var regexp = new $RegExp(re);
var s = TO_STRING_INLINE(this);
- var last_idx = regexp.lastIndex; // keep old lastIndex
- regexp.lastIndex = 0; // ignore re.global property
- var result = regexp.exec(s);
- regexp.lastIndex = last_idx; // restore lastIndex
- if (result == null)
- return -1;
- else
- return result.index;
+ var match = DoRegExpExec(regexp, s, 0);
+ if (match) {
+ lastMatchInfo = match;
+ return match[CAPTURE0];
+ }
+ return -1;
}
« 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