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

Side by Side Diff: src/regexp.js

Issue 9701064: Experimental profiler: split RegExp.test() for better optimization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed bug and added test coverage. Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/regexp.js » ('j') | test/mjsunit/regexp.js » ('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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 return false; 243 return false;
244 } 244 }
245 lastMatchInfoOverride = null; 245 lastMatchInfoOverride = null;
246 this.lastIndex = lastMatchInfo[CAPTURE1]; 246 this.lastIndex = lastMatchInfo[CAPTURE1];
247 return true; 247 return true;
248 } else { 248 } else {
249 // Non-global regexp. 249 // Non-global regexp.
250 // Remove irrelevant preceeding '.*' in a non-global test regexp. 250 // Remove irrelevant preceeding '.*' in a non-global test regexp.
251 // The expression checks whether this.source starts with '.*' and 251 // The expression checks whether this.source starts with '.*' and
252 // that the third char is not a '?'. 252 // that the third char is not a '?'.
253 if (%_StringCharCodeAt(this.source, 0) == 46 && // '.' 253 var regexp = this;
254 %_StringCharCodeAt(this.source, 1) == 42 && // '*' 254 if (%_StringCharCodeAt(regexp.source, 0) == 46 && // '.'
255 %_StringCharCodeAt(this.source, 2) != 63) { // '?' 255 %_StringCharCodeAt(regexp.source, 1) == 42 && // '*'
256 if (!%_ObjectEquals(regexp_key, this)) { 256 %_StringCharCodeAt(regexp.source, 2) != 63) { // '?'
257 regexp_key = this; 257 regexp = TrimRegExp(regexp);
258 regexp_val = new $RegExp(SubString(this.source, 2, this.source.length),
259 (!this.ignoreCase
260 ? !this.multiline ? "" : "m"
261 : !this.multiline ? "i" : "im"));
262 }
263 if (%_RegExpExec(regexp_val, string, 0, lastMatchInfo) === null) {
264 return false;
265 }
266 } 258 }
267 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [this, string, lastIndex]); 259 %_Log('regexp', 'regexp-exec,%0r,%1S,%2i', [regexp, string, lastIndex]);
268 // matchIndices is either null or the lastMatchInfo array. 260 // matchIndices is either null or the lastMatchInfo array.
269 var matchIndices = %_RegExpExec(this, string, 0, lastMatchInfo); 261 var matchIndices = %_RegExpExec(regexp, string, 0, lastMatchInfo);
270 if (matchIndices === null) return false; 262 if (matchIndices === null) return false;
271 lastMatchInfoOverride = null; 263 lastMatchInfoOverride = null;
272 return true; 264 return true;
273 } 265 }
274 } 266 }
275 267
268 function TrimRegExp(regexp) {
269 if (!%_ObjectEquals(regexp_key, regexp)) {
270 regexp_key = regexp;
271 regexp_val =
272 new $RegExp(SubString(regexp.source, 2, regexp.source.length),
273 (regexp.ignoreCase ? regexp.multiline ? "im" : "i"
274 : regexp.multiline ? "m" : ""));
275 }
276 return regexp_val;
277 }
278
276 279
277 function RegExpToString() { 280 function RegExpToString() {
278 // If this.source is an empty string, output /(?:)/. 281 // If this.source is an empty string, output /(?:)/.
279 // http://bugzilla.mozilla.org/show_bug.cgi?id=225550 282 // http://bugzilla.mozilla.org/show_bug.cgi?id=225550
280 // ecma_2/RegExp/properties-001.js. 283 // ecma_2/RegExp/properties-001.js.
281 var src = this.source ? this.source : '(?:)'; 284 var src = this.source ? this.source : '(?:)';
282 var result = '/' + src + '/'; 285 var result = '/' + src + '/';
283 if (this.global) result += 'g'; 286 if (this.global) result += 'g';
284 if (this.ignoreCase) result += 'i'; 287 if (this.ignoreCase) result += 'i';
285 if (this.multiline) result += 'm'; 288 if (this.multiline) result += 'm';
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 NoOpSetter, DONT_ENUM | DONT_DELETE); 474 NoOpSetter, DONT_ENUM | DONT_DELETE);
472 475
473 for (var i = 1; i < 10; ++i) { 476 for (var i = 1; i < 10; ++i) {
474 %DefineOrRedefineAccessorProperty($RegExp, '$' + i, 477 %DefineOrRedefineAccessorProperty($RegExp, '$' + i,
475 RegExpMakeCaptureGetter(i), NoOpSetter, 478 RegExpMakeCaptureGetter(i), NoOpSetter,
476 DONT_DELETE); 479 DONT_DELETE);
477 } 480 }
478 } 481 }
479 482
480 SetUpRegExp(); 483 SetUpRegExp();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regexp.js » ('j') | test/mjsunit/regexp.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698