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

Side by Side Diff: src/string.js

Issue 2989: Avoid the KMP overhead for simple indexOf() operations. (Closed)
Patch Set: Typo Created 12 years, 3 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
« src/runtime.cc ('K') | « src/runtime.cc ('k') | 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-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 325 }
326 parameters[j] = index; 326 parameters[j] = index;
327 parameters[j + 1] = subject; 327 parameters[j + 1] = subject;
328 return ToString(replace.apply(null, parameters)); 328 return ToString(replace.apply(null, parameters));
329 } 329 }
330 330
331 331
332 // ECMA-262 section 15.5.4.7 332 // ECMA-262 section 15.5.4.7
333 %AddProperty($String.prototype, "indexOf", function(searchString /* position */) { // length == 1 333 %AddProperty($String.prototype, "indexOf", function(searchString /* position */) { // length == 1
334 var str = ToString(this); 334 var str = ToString(this);
335 var str_len = str.length;
335 var searchStr = ToString(searchString); 336 var searchStr = ToString(searchString);
336 var index = 0; 337 var index = 0;
337 if (%_ArgumentsLength() > 1) { 338 if (%_ArgumentsLength() > 1) {
338 var arg1 = %_Arguments(1); // position 339 var arg1 = %_Arguments(1); // position
339 index = TO_INTEGER(arg1); 340 index = TO_INTEGER(arg1);
340 } 341 }
341 if (index < 0) index = 0; 342 if (index < 0) index = 0;
342 if (index > str.length) index = str.length; 343 if (index > str_len) index = str_len;
343 if (searchStr.length + index > str.length) return -1; 344 if (searchStr.length + index > str_len) return -1;
344 return %StringIndexOf(str, searchStr, index); 345 return %StringIndexOf(str, searchStr, index);
345 }, DONT_ENUM); 346 }, DONT_ENUM);
346 347
347 348
348 // ECMA-262 section 15.5.4.8 349 // ECMA-262 section 15.5.4.8
349 %AddProperty($String.prototype, "lastIndexOf", function(searchString /* position */) { // length == 1 350 %AddProperty($String.prototype, "lastIndexOf", function(searchString /* position */) { // length == 1
350 var sub = ToString(this); 351 var sub = ToString(this);
351 var pat = ToString(searchString); 352 var pat = ToString(searchString);
352 var index = (%_ArgumentsLength() > 1) 353 var index = (%_ArgumentsLength() > 1)
353 ? ToNumber(%_Arguments(1) /* position */) 354 ? ToNumber(%_Arguments(1) /* position */)
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 763
763 764
764 StringBuilder.prototype.generate = function() { 765 StringBuilder.prototype.generate = function() {
765 return %StringBuilderConcat(this.elements, ""); 766 return %StringBuilderConcat(this.elements, "");
766 } 767 }
767 768
768 769
769 ReplaceResultBuilder.prototype.generate = function() { 770 ReplaceResultBuilder.prototype.generate = function() {
770 return %StringBuilderConcat(this.elements, this.special_string); 771 return %StringBuilderConcat(this.elements, this.special_string);
771 } 772 }
OLDNEW
« src/runtime.cc ('K') | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698