OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/regexp/jsregexp-inl.h" | 8 #include "src/regexp/jsregexp-inl.h" |
9 #include "src/string-builder.h" | 9 #include "src/string-builder.h" |
10 #include "src/string-search.h" | 10 #include "src/string-search.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } else { | 186 } else { |
187 position = StringMatchBackwards(sub_content.ToUC16Vector(), pat_vector, | 187 position = StringMatchBackwards(sub_content.ToUC16Vector(), pat_vector, |
188 start_index); | 188 start_index); |
189 } | 189 } |
190 } | 190 } |
191 | 191 |
192 return Smi::FromInt(position); | 192 return Smi::FromInt(position); |
193 } | 193 } |
194 | 194 |
195 | 195 |
196 RUNTIME_FUNCTION(Runtime_StringLocaleCompare) { | |
197 HandleScope handle_scope(isolate); | |
198 DCHECK(args.length() == 2); | |
199 | |
200 CONVERT_ARG_HANDLE_CHECKED(String, str1, 0); | |
201 CONVERT_ARG_HANDLE_CHECKED(String, str2, 1); | |
202 | |
203 if (str1.is_identical_to(str2)) return Smi::FromInt(0); // Equal. | |
204 int str1_length = str1->length(); | |
205 int str2_length = str2->length(); | |
206 | |
207 // Decide trivial cases without flattening. | |
208 if (str1_length == 0) { | |
209 if (str2_length == 0) return Smi::FromInt(0); // Equal. | |
210 return Smi::FromInt(-str2_length); | |
211 } else { | |
212 if (str2_length == 0) return Smi::FromInt(str1_length); | |
213 } | |
214 | |
215 int end = str1_length < str2_length ? str1_length : str2_length; | |
216 | |
217 // No need to flatten if we are going to find the answer on the first | |
218 // character. At this point we know there is at least one character | |
219 // in each string, due to the trivial case handling above. | |
220 int d = str1->Get(0) - str2->Get(0); | |
221 if (d != 0) return Smi::FromInt(d); | |
222 | |
223 str1 = String::Flatten(str1); | |
224 str2 = String::Flatten(str2); | |
225 | |
226 DisallowHeapAllocation no_gc; | |
227 String::FlatContent flat1 = str1->GetFlatContent(); | |
228 String::FlatContent flat2 = str2->GetFlatContent(); | |
229 | |
230 for (int i = 0; i < end; i++) { | |
231 if (flat1.Get(i) != flat2.Get(i)) { | |
232 return Smi::FromInt(flat1.Get(i) - flat2.Get(i)); | |
233 } | |
234 } | |
235 | |
236 return Smi::FromInt(str1_length - str2_length); | |
237 } | |
238 | |
239 | |
240 RUNTIME_FUNCTION(Runtime_SubString) { | 196 RUNTIME_FUNCTION(Runtime_SubString) { |
241 HandleScope scope(isolate); | 197 HandleScope scope(isolate); |
242 DCHECK(args.length() == 3); | 198 DCHECK(args.length() == 3); |
243 | 199 |
244 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); | 200 CONVERT_ARG_HANDLE_CHECKED(String, string, 0); |
245 int start, end; | 201 int start, end; |
246 // We have a fast integer-only case here to avoid a conversion to double in | 202 // We have a fast integer-only case here to avoid a conversion to double in |
247 // the common case where from and to are Smis. | 203 // the common case where from and to are Smis. |
248 if (args[1]->IsSmi() && args[2]->IsSmi()) { | 204 if (args[1]->IsSmi() && args[2]->IsSmi()) { |
249 CONVERT_SMI_ARG_CHECKED(from_number, 1); | 205 CONVERT_SMI_ARG_CHECKED(from_number, 1); |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 SealHandleScope shs(isolate); | 1130 SealHandleScope shs(isolate); |
1175 DCHECK(args.length() == 2); | 1131 DCHECK(args.length() == 2); |
1176 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); | 1132 if (!args[0]->IsString()) return isolate->heap()->undefined_value(); |
1177 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); | 1133 if (!args[1]->IsNumber()) return isolate->heap()->undefined_value(); |
1178 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); | 1134 if (std::isinf(args.number_at(1))) return isolate->heap()->nan_value(); |
1179 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); | 1135 return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate); |
1180 } | 1136 } |
1181 | 1137 |
1182 } // namespace internal | 1138 } // namespace internal |
1183 } // namespace v8 | 1139 } // namespace v8 |
OLD | NEW |