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

Side by Side Diff: src/string.js

Issue 6489028: Improve StringIndexOf. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 10 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 | 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-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 return %StringBuilderConcat(parts, len + 1, ""); 96 return %StringBuilderConcat(parts, len + 1, "");
97 } 97 }
98 98
99 // Match ES3 and Safari 99 // Match ES3 and Safari
100 %FunctionSetLength(StringConcat, 1); 100 %FunctionSetLength(StringConcat, 1);
101 101
102 102
103 // ECMA-262 section 15.5.4.7 103 // ECMA-262 section 15.5.4.7
104 function StringIndexOf(pattern /* position */) { // length == 1 104 function StringIndexOf(pattern /* position */) { // length == 1
105 var subject = TO_STRING_INLINE(this); 105 var subject = TO_STRING_INLINE(this);
106 var pattern = TO_STRING_INLINE(pattern);
107 var subject_len = subject.length;
108 var pattern_len = pattern.length;
109 var index = 0; 106 var index = 0;
110 if (%_ArgumentsLength() > 1) { 107 if (%_ArgumentsLength() > 1) {
111 var arg1 = %_Arguments(1); // position 108 index = %_Arguments(1); // position
112 index = TO_INTEGER(arg1); 109 index = TO_INTEGER(index);
110 if (index < 0) index = 0;
111 if (index > subject.length) index = subject.length;
113 } 112 }
114 if (index < 0) index = 0; 113 return %StringIndexOf(subject, TO_STRING_INLINE(pattern), index);
115 if (index > subject_len) index = subject_len;
116 if (pattern_len + index > subject_len) return -1;
117 return %StringIndexOf(subject, pattern, index);
118 } 114 }
119 115
120 116
121 // ECMA-262 section 15.5.4.8 117 // ECMA-262 section 15.5.4.8
122 function StringLastIndexOf(pat /* position */) { // length == 1 118 function StringLastIndexOf(pat /* position */) { // length == 1
123 var sub = TO_STRING_INLINE(this); 119 var sub = TO_STRING_INLINE(this);
124 var subLength = sub.length; 120 var subLength = sub.length;
125 var pat = TO_STRING_INLINE(pat); 121 var pat = TO_STRING_INLINE(pat);
126 var patLength = pat.length; 122 var patLength = pat.length;
127 var index = subLength - patLength; 123 var index = subLength - patLength;
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 "italics", StringItalics, 907 "italics", StringItalics,
912 "small", StringSmall, 908 "small", StringSmall,
913 "strike", StringStrike, 909 "strike", StringStrike,
914 "sub", StringSub, 910 "sub", StringSub,
915 "sup", StringSup 911 "sup", StringSup
916 )); 912 ));
917 } 913 }
918 914
919 915
920 SetupString(); 916 SetupString();
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