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

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 | « no previous file | src/zone.cc » ('j') | src/zone.cc » ('J')
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
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. Inline ToInteger() manually.
188 ToInteger(regexp.lastIndex); 188 if (! %_IsSmi(regexp.lastIndex)) {
189 ToNumber(regexp.lastIndex);
190 }
189 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0); 191 if (!regexp.global) return RegExpExecNoTests(regexp, subject, 0);
190 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]); 192 %_Log('regexp', 'regexp-match,%0S,%1r', [subject, regexp]);
191 // lastMatchInfo is defined in regexp.js. 193 // lastMatchInfo is defined in regexp.js.
192 var result = %StringMatch(subject, regexp, lastMatchInfo); 194 var result = %StringMatch(subject, regexp, lastMatchInfo);
193 if (result !== null) lastMatchInfoOverride = null; 195 if (result !== null) lastMatchInfoOverride = null;
194 regexp.lastIndex = 0; 196 regexp.lastIndex = 0;
195 return result; 197 return result;
196 } 198 }
197 // Non-regexp argument. 199 // Non-regexp argument.
198 regexp = new $RegExp(regexp); 200 regexp = new $RegExp(regexp);
(...skipping 29 matching lines...) Expand all
228 // .... function replace 230 // .... function replace
229 // ...... global search 231 // ...... global search
230 // ...... non-global search 232 // ...... non-global search
231 // .. string search 233 // .. string search
232 // .... special case that replaces with one single character 234 // .... special case that replaces with one single character
233 // ...... function replace 235 // ...... function replace
234 // ...... string replace (with $-expansion) 236 // ...... string replace (with $-expansion)
235 237
236 if (IS_REGEXP(search)) { 238 if (IS_REGEXP(search)) {
237 // Emulate RegExp.prototype.exec's side effect in step 5, even if 239 // Emulate RegExp.prototype.exec's side effect in step 5, even if
238 // value is discarded. 240 // value is discarded. Inline ToInteger() manually.
239 ToInteger(search.lastIndex); 241 if (! %_IsSmi(search.lastIndex)) {
242 ToNumber(search.lastIndex);
243 }
240 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]); 244 %_Log('regexp', 'regexp-replace,%0r,%1S', [search, subject]);
241 245
242 if (!IS_SPEC_FUNCTION(replace)) { 246 if (!IS_SPEC_FUNCTION(replace)) {
243 replace = TO_STRING_INLINE(replace); 247 replace = TO_STRING_INLINE(replace);
244 248
245 if (!search.global) { 249 if (!search.global) {
246 // Non-global regexp search, string replace. 250 // Non-global regexp search, string replace.
247 var match = DoRegExpExec(search, subject, 0); 251 var match = DoRegExpExec(search, subject, 0);
248 if (match == null) { 252 if (match == null) {
249 search.lastIndex = 0 253 search.lastIndex = 0
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 "fixed", StringFixed, 1010 "fixed", StringFixed,
1007 "italics", StringItalics, 1011 "italics", StringItalics,
1008 "small", StringSmall, 1012 "small", StringSmall,
1009 "strike", StringStrike, 1013 "strike", StringStrike,
1010 "sub", StringSub, 1014 "sub", StringSub,
1011 "sup", StringSup 1015 "sup", StringSup
1012 )); 1016 ));
1013 } 1017 }
1014 1018
1015 SetUpString(); 1019 SetUpString();
OLDNEW
« no previous file with comments | « no previous file | src/zone.cc » ('j') | src/zone.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698