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

Side by Side Diff: src/string.js

Issue 18057004: Refactored code a bit to improve StringReplace performance (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/macros.py ('k') | src/zone.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // ECMA-262 section 15.5.4.10 178 // ECMA-262 section 15.5.4.10
179 function StringMatch(regexp) { 179 function StringMatch(regexp) {
180 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { 180 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) {
181 throw MakeTypeError("called_on_null_or_undefined", 181 throw MakeTypeError("called_on_null_or_undefined",
182 ["String.prototype.match"]); 182 ["String.prototype.match"]);
183 } 183 }
184 var subject = TO_STRING_INLINE(this); 184 var subject = TO_STRING_INLINE(this);
185 if (IS_REGEXP(regexp)) { 185 if (IS_REGEXP(regexp)) {
186 // Emulate RegExp.prototype.exec's side effect in step 5, even though 186 // Emulate RegExp.prototype.exec's side effect in step 5, even though
187 // value is discarded. 187 // value is discarded.
188 ToInteger(regexp.lastIndex); 188 var lastIndex = regexp.lastIndex;
189 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex);
189 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); 190 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0);
190 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); 191 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]);
191 // lastMatchInfo is defined in regexp.js. 192 // lastMatchInfo is defined in regexp.js.
192 var result = %StringMatch(subject, regexp, lastMatchInfo); 193 var result = %StringMatch(subject, regexp, lastMatchInfo);
193 if (result !== null) lastMatchInfoOverride = null; 194 if (result !== null) lastMatchInfoOverride = null;
194 regexp.lastIndex = 0; 195 regexp.lastIndex = 0;
195 return result; 196 return result;
196 } 197 }
197 // Non-regexp argument. 198 // Non-regexp argument.
198 regexp = new $RegExp(regexp); 199 regexp = new $RegExp(regexp);
(...skipping 30 matching lines...) Expand all
229 // ...... global search 230 // ...... global search
230 // ...... non-global search 231 // ...... non-global search
231 // .. string search 232 // .. string search
232 // .... special case that replaces with one single character 233 // .... special case that replaces with one single character
233 // ...... function replace 234 // ...... function replace
234 // ...... string replace (with $-expansion) 235 // ...... string replace (with $-expansion)
235 236
236 if (IS_REGEXP(search)) { 237 if (IS_REGEXP(search)) {
237 // Emulate RegExp.prototype.exec's side effect in step 5, even if 238 // Emulate RegExp.prototype.exec's side effect in step 5, even if
238 // value is discarded. 239 // value is discarded.
239 ToInteger(search.lastIndex); 240 var lastIndex = search.lastIndex;
241 TO_INTEGER_FOR_SIDE_EFFECT(lastIndex);
240 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); 242 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]);
241 243
242 if (!IS_SPEC_FUNCTION(replace)) { 244 if (!IS_SPEC_FUNCTION(replace)) {
243 replace = TO_STRING_INLINE(replace); 245 replace = TO_STRING_INLINE(replace);
244 246
245 if (!search.global) { 247 if (!search.global) {
246 // Non-global regexp search, string replace. 248 // Non-global regexp search, string replace.
247 var match = DoRegExpExec(search, subject, 0); 249 var match = DoRegExpExec(search, subject, 0);
248 if (match == null) { 250 if (match == null) {
249 search.lastIndex = 0 251 search.lastIndex = 0
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 "fixed", StringFixed, 1008 "fixed", StringFixed,
1007 "italics", StringItalics, 1009 "italics", StringItalics,
1008 "small", StringSmall, 1010 "small", StringSmall,
1009 "strike", StringStrike, 1011 "strike", StringStrike,
1010 "sub", StringSub, 1012 "sub", StringSub,
1011 "sup", StringSup 1013 "sup", StringSup
1012 )); 1014 ));
1013 } 1015 }
1014 1016
1015 SetUpString(); 1017 SetUpString();
OLDNEW
« no previous file with comments | « src/macros.py ('k') | src/zone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698