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

Side by Side Diff: src/string.js

Issue 2987: Don't try an indexOf() when the search string is bigger than the string. (Closed)
Patch Set: 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
« 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-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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 searchStr = ToString(searchString); 335 var searchStr = ToString(searchString);
336 var index = 0; 336 var index = 0;
337 if (%_ArgumentsLength() > 1) { 337 if (%_ArgumentsLength() > 1) {
338 var arg1 = %_Arguments(1); // position 338 var arg1 = %_Arguments(1); // position
339 index = TO_INTEGER(arg1); 339 index = TO_INTEGER(arg1);
340 } 340 }
341 if (index < 0) index = 0; 341 if (index < 0) index = 0;
342 if (index > str.length) index = str.length; 342 if (index > str.length) index = str.length;
343 if (searchStr.length + index > str.length) return -1;
343 return %StringIndexOf(str, searchStr, index); 344 return %StringIndexOf(str, searchStr, index);
344 }, DONT_ENUM); 345 }, DONT_ENUM);
345 346
346 347
347 // ECMA-262 section 15.5.4.8 348 // ECMA-262 section 15.5.4.8
348 %AddProperty($String.prototype, "lastIndexOf", function(searchString /* position */) { // length == 1 349 %AddProperty($String.prototype, "lastIndexOf", function(searchString /* position */) { // length == 1
349 var sub = ToString(this); 350 var sub = ToString(this);
350 var pat = ToString(searchString); 351 var pat = ToString(searchString);
351 var index = (%_ArgumentsLength() > 1) 352 var index = (%_ArgumentsLength() > 1)
352 ? ToNumber(%_Arguments(1) /* position */) 353 ? ToNumber(%_Arguments(1) /* position */)
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 762
762 763
763 StringBuilder.prototype.generate = function() { 764 StringBuilder.prototype.generate = function() {
764 return %StringBuilderConcat(this.elements, ""); 765 return %StringBuilderConcat(this.elements, "");
765 } 766 }
766 767
767 768
768 ReplaceResultBuilder.prototype.generate = function() { 769 ReplaceResultBuilder.prototype.generate = function() {
769 return %StringBuilderConcat(this.elements, this.special_string); 770 return %StringBuilderConcat(this.elements, this.special_string);
770 } 771 }
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