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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // ECMA-262 section 15.5.4.12 524 // ECMA-262 section 15.5.4.12
525 function StringSearch(re) { 525 function StringSearch(re) {
526 var regexp = new $RegExp(re); 526 var regexp = new $RegExp(re);
527 var s = TO_STRING_INLINE(this); 527 var s = TO_STRING_INLINE(this);
528 var last_idx = regexp.lastIndex; // keep old lastIndex 528 var match = DoRegExpExec(regexp, s, 0);
529 regexp.lastIndex = 0; // ignore re.global property 529 if (match) {
530 var result = regexp.exec(s); 530 lastMatchInfo = match;
531 regexp.lastIndex = last_idx; // restore lastIndex 531 return match[CAPTURE0];
532 if (result == null) 532 }
533 return -1; 533 return -1;
534 else
535 return result.index;
536 } 534 }
537 535
538 536
539 // ECMA-262 section 15.5.4.13 537 // ECMA-262 section 15.5.4.13
540 function StringSlice(start, end) { 538 function StringSlice(start, end) {
541 var s = TO_STRING_INLINE(this); 539 var s = TO_STRING_INLINE(this);
542 var s_len = s.length; 540 var s_len = s.length;
543 var start_i = TO_INTEGER(start); 541 var start_i = TO_INTEGER(start);
544 var end_i = s_len; 542 var end_i = s_len;
545 if (end !== void 0) 543 if (end !== void 0)
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 "small", StringSmall, 984 "small", StringSmall,
987 "strike", StringStrike, 985 "strike", StringStrike,
988 "sub", StringSub, 986 "sub", StringSub,
989 "sup", StringSup, 987 "sup", StringSup,
990 "toJSON", StringToJSON 988 "toJSON", StringToJSON
991 )); 989 ));
992 } 990 }
993 991
994 992
995 SetupString(); 993 SetupString();
OLDNEW
« 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