Revision: 6747
Author: [email protected]
Date: Fri Feb 11 04:33:30 2011
Log: Improve StringIndexOf.
Review URL: http://codereview.chromium.org/6489028
http://code.google.com/p/v8/source/detail?r=6747
Modified:
/branches/bleeding_edge/src/string.js
=======================================
--- /branches/bleeding_edge/src/string.js Wed Dec 22 05:19:25 2010
+++ /branches/bleeding_edge/src/string.js Fri Feb 11 04:33:30 2011
@@ -103,18 +103,14 @@
// ECMA-262 section 15.5.4.7
function StringIndexOf(pattern /* position */) { // length == 1
var subject = TO_STRING_INLINE(this);
- var pattern = TO_STRING_INLINE(pattern);
- var subject_len = subject.length;
- var pattern_len = pattern.length;
var index = 0;
if (%_ArgumentsLength() > 1) {
- var arg1 = %_Arguments(1); // position
- index = TO_INTEGER(arg1);
- }
- if (index < 0) index = 0;
- if (index > subject_len) index = subject_len;
- if (pattern_len + index > subject_len) return -1;
- return %StringIndexOf(subject, pattern, index);
+ index = %_Arguments(1); // position
+ index = TO_INTEGER(index);
+ if (index < 0) index = 0;
+ if (index > subject.length) index = subject.length;
+ }
+ return %StringIndexOf(subject, TO_STRING_INLINE(pattern), index);
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev