OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 2645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2656 } | 2656 } |
2657 | 2657 |
2658 ZoneList<ReplacementPart> parts_; | 2658 ZoneList<ReplacementPart> parts_; |
2659 ZoneList<Handle<String> > replacement_substrings_; | 2659 ZoneList<Handle<String> > replacement_substrings_; |
2660 }; | 2660 }; |
2661 | 2661 |
2662 | 2662 |
2663 void CompiledReplacement::Compile(Handle<String> replacement, | 2663 void CompiledReplacement::Compile(Handle<String> replacement, |
2664 int capture_count, | 2664 int capture_count, |
2665 int subject_length) { | 2665 int subject_length) { |
2666 ASSERT(replacement->IsFlat()); | 2666 { |
2667 if (replacement->IsAsciiRepresentation()) { | |
2668 AssertNoAllocation no_alloc; | 2667 AssertNoAllocation no_alloc; |
2669 ParseReplacementPattern(&parts_, | 2668 String::FlatContent content = replacement->GetFlatContent(); |
2670 replacement->ToAsciiVector(), | 2669 ASSERT(content.IsFlat()); |
2671 capture_count, | 2670 if (content.IsAscii()) { |
2672 subject_length); | 2671 ParseReplacementPattern(&parts_, |
2673 } else { | 2672 content.ToAsciiVector(), |
2674 ASSERT(replacement->IsTwoByteRepresentation()); | 2673 capture_count, |
2675 AssertNoAllocation no_alloc; | 2674 subject_length); |
2676 | 2675 } else { |
2677 ParseReplacementPattern(&parts_, | 2676 ASSERT(content.IsTwoByte()); |
2678 replacement->ToUC16Vector(), | 2677 ParseReplacementPattern(&parts_, |
2679 capture_count, | 2678 content.ToUC16Vector(), |
2680 subject_length); | 2679 capture_count, |
| 2680 subject_length); |
| 2681 } |
2681 } | 2682 } |
2682 Isolate* isolate = replacement->GetIsolate(); | 2683 Isolate* isolate = replacement->GetIsolate(); |
2683 // Find substrings of replacement string and create them as String objects. | 2684 // Find substrings of replacement string and create them as String objects. |
2684 int substring_index = 0; | 2685 int substring_index = 0; |
2685 for (int i = 0, n = parts_.length(); i < n; i++) { | 2686 for (int i = 0, n = parts_.length(); i < n; i++) { |
2686 int tag = parts_[i].tag; | 2687 int tag = parts_[i].tag; |
2687 if (tag <= 0) { // A replacement string slice. | 2688 if (tag <= 0) { // A replacement string slice. |
2688 int from = -tag; | 2689 int from = -tag; |
2689 int to = parts_[i].data; | 2690 int to = parts_[i].data; |
2690 replacement_substrings_.Add( | 2691 replacement_substrings_.Add( |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3042 if (pattern_length == 0) return start_index; | 3043 if (pattern_length == 0) return start_index; |
3043 | 3044 |
3044 int subject_length = sub->length(); | 3045 int subject_length = sub->length(); |
3045 if (start_index + pattern_length > subject_length) return -1; | 3046 if (start_index + pattern_length > subject_length) return -1; |
3046 | 3047 |
3047 if (!sub->IsFlat()) FlattenString(sub); | 3048 if (!sub->IsFlat()) FlattenString(sub); |
3048 if (!pat->IsFlat()) FlattenString(pat); | 3049 if (!pat->IsFlat()) FlattenString(pat); |
3049 | 3050 |
3050 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid | 3051 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid |
3051 // Extract flattened substrings of cons strings before determining asciiness. | 3052 // Extract flattened substrings of cons strings before determining asciiness. |
3052 String* seq_sub = *sub; | 3053 String::FlatContent seq_sub = sub->GetFlatContent(); |
3053 if (seq_sub->IsConsString()) seq_sub = ConsString::cast(seq_sub)->first(); | 3054 String::FlatContent seq_pat = pat->GetFlatContent(); |
3054 String* seq_pat = *pat; | |
3055 if (seq_pat->IsConsString()) seq_pat = ConsString::cast(seq_pat)->first(); | |
3056 | 3055 |
3057 // dispatch on type of strings | 3056 // dispatch on type of strings |
3058 if (seq_pat->IsAsciiRepresentation()) { | 3057 if (seq_pat.IsAscii()) { |
3059 Vector<const char> pat_vector = seq_pat->ToAsciiVector(); | 3058 Vector<const char> pat_vector = seq_pat.ToAsciiVector(); |
3060 if (seq_sub->IsAsciiRepresentation()) { | 3059 if (seq_sub.IsAscii()) { |
3061 return SearchString(isolate, | 3060 return SearchString(isolate, |
3062 seq_sub->ToAsciiVector(), | 3061 seq_sub.ToAsciiVector(), |
3063 pat_vector, | 3062 pat_vector, |
3064 start_index); | 3063 start_index); |
3065 } | 3064 } |
3066 return SearchString(isolate, | 3065 return SearchString(isolate, |
3067 seq_sub->ToUC16Vector(), | 3066 seq_sub.ToUC16Vector(), |
3068 pat_vector, | 3067 pat_vector, |
3069 start_index); | 3068 start_index); |
3070 } | 3069 } |
3071 Vector<const uc16> pat_vector = seq_pat->ToUC16Vector(); | 3070 Vector<const uc16> pat_vector = seq_pat.ToUC16Vector(); |
3072 if (seq_sub->IsAsciiRepresentation()) { | 3071 if (seq_sub.IsAscii()) { |
3073 return SearchString(isolate, | 3072 return SearchString(isolate, |
3074 seq_sub->ToAsciiVector(), | 3073 seq_sub.ToAsciiVector(), |
3075 pat_vector, | 3074 pat_vector, |
3076 start_index); | 3075 start_index); |
3077 } | 3076 } |
3078 return SearchString(isolate, | 3077 return SearchString(isolate, |
3079 seq_sub->ToUC16Vector(), | 3078 seq_sub.ToUC16Vector(), |
3080 pat_vector, | 3079 pat_vector, |
3081 start_index); | 3080 start_index); |
3082 } | 3081 } |
3083 | 3082 |
3084 | 3083 |
3085 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringIndexOf) { | 3084 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringIndexOf) { |
3086 HandleScope scope(isolate); // create a new handle scope | 3085 HandleScope scope(isolate); // create a new handle scope |
3087 ASSERT(args.length() == 3); | 3086 ASSERT(args.length() == 3); |
3088 | 3087 |
3089 CONVERT_ARG_CHECKED(String, sub, 0); | 3088 CONVERT_ARG_CHECKED(String, sub, 0); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3154 | 3153 |
3155 if (pat_length == 0) { | 3154 if (pat_length == 0) { |
3156 return Smi::FromInt(start_index); | 3155 return Smi::FromInt(start_index); |
3157 } | 3156 } |
3158 | 3157 |
3159 if (!sub->IsFlat()) FlattenString(sub); | 3158 if (!sub->IsFlat()) FlattenString(sub); |
3160 if (!pat->IsFlat()) FlattenString(pat); | 3159 if (!pat->IsFlat()) FlattenString(pat); |
3161 | 3160 |
3162 int position = -1; | 3161 int position = -1; |
3163 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid | 3162 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid |
3164 // Extract flattened substrings of cons strings before determining asciiness. | |
3165 String* seq_sub = *sub; | |
3166 if (seq_sub->IsConsString()) seq_sub = ConsString::cast(seq_sub)->first(); | |
3167 String* seq_pat = *pat; | |
3168 if (seq_pat->IsConsString()) seq_pat = ConsString::cast(seq_pat)->first(); | |
3169 | 3163 |
3170 if (seq_pat->IsAsciiRepresentation()) { | 3164 String::FlatContent sub_content = sub->GetFlatContent(); |
3171 Vector<const char> pat_vector = seq_pat->ToAsciiVector(); | 3165 String::FlatContent pat_content = pat->GetFlatContent(); |
3172 if (seq_sub->IsAsciiRepresentation()) { | 3166 |
3173 position = StringMatchBackwards(seq_sub->ToAsciiVector(), | 3167 if (pat_content.IsAscii()) { |
| 3168 Vector<const char> pat_vector = pat_content.ToAsciiVector(); |
| 3169 if (sub_content.IsAscii()) { |
| 3170 position = StringMatchBackwards(sub_content.ToAsciiVector(), |
3174 pat_vector, | 3171 pat_vector, |
3175 start_index); | 3172 start_index); |
3176 } else { | 3173 } else { |
3177 position = StringMatchBackwards(seq_sub->ToUC16Vector(), | 3174 position = StringMatchBackwards(sub_content.ToUC16Vector(), |
3178 pat_vector, | 3175 pat_vector, |
3179 start_index); | 3176 start_index); |
3180 } | 3177 } |
3181 } else { | 3178 } else { |
3182 Vector<const uc16> pat_vector = seq_pat->ToUC16Vector(); | 3179 Vector<const uc16> pat_vector = pat_content.ToUC16Vector(); |
3183 if (seq_sub->IsAsciiRepresentation()) { | 3180 if (sub_content.IsAscii()) { |
3184 position = StringMatchBackwards(seq_sub->ToAsciiVector(), | 3181 position = StringMatchBackwards(sub_content.ToAsciiVector(), |
3185 pat_vector, | 3182 pat_vector, |
3186 start_index); | 3183 start_index); |
3187 } else { | 3184 } else { |
3188 position = StringMatchBackwards(seq_sub->ToUC16Vector(), | 3185 position = StringMatchBackwards(sub_content.ToUC16Vector(), |
3189 pat_vector, | 3186 pat_vector, |
3190 start_index); | 3187 start_index); |
3191 } | 3188 } |
3192 } | 3189 } |
3193 | 3190 |
3194 return Smi::FromInt(position); | 3191 return Smi::FromInt(position); |
3195 } | 3192 } |
3196 | 3193 |
3197 | 3194 |
3198 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringLocaleCompare) { | 3195 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringLocaleCompare) { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3396 FixedArrayBuilder* builder) { | 3393 FixedArrayBuilder* builder) { |
3397 ASSERT(subject->IsFlat()); | 3394 ASSERT(subject->IsFlat()); |
3398 ASSERT(pattern->IsFlat()); | 3395 ASSERT(pattern->IsFlat()); |
3399 | 3396 |
3400 // Treating as if a previous match was before first character. | 3397 // Treating as if a previous match was before first character. |
3401 int match_pos = -pattern->length(); | 3398 int match_pos = -pattern->length(); |
3402 | 3399 |
3403 for (;;) { // Break when search complete. | 3400 for (;;) { // Break when search complete. |
3404 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch); | 3401 builder->EnsureCapacity(kMaxBuilderEntriesPerRegExpMatch); |
3405 AssertNoAllocation no_gc; | 3402 AssertNoAllocation no_gc; |
3406 if (subject->IsAsciiRepresentation()) { | 3403 String::FlatContent subject_content = subject->GetFlatContent(); |
3407 Vector<const char> subject_vector = subject->ToAsciiVector(); | 3404 String::FlatContent pattern_content = pattern->GetFlatContent(); |
3408 if (pattern->IsAsciiRepresentation()) { | 3405 if (subject_content.IsAscii()) { |
| 3406 Vector<const char> subject_vector = subject_content.ToAsciiVector(); |
| 3407 if (pattern_content.IsAscii()) { |
3409 if (SearchStringMultiple(isolate, | 3408 if (SearchStringMultiple(isolate, |
3410 subject_vector, | 3409 subject_vector, |
3411 pattern->ToAsciiVector(), | 3410 pattern_content.ToAsciiVector(), |
3412 *pattern, | 3411 *pattern, |
3413 builder, | 3412 builder, |
3414 &match_pos)) break; | 3413 &match_pos)) break; |
3415 } else { | 3414 } else { |
3416 if (SearchStringMultiple(isolate, | 3415 if (SearchStringMultiple(isolate, |
3417 subject_vector, | 3416 subject_vector, |
3418 pattern->ToUC16Vector(), | 3417 pattern_content.ToUC16Vector(), |
3419 *pattern, | 3418 *pattern, |
3420 builder, | 3419 builder, |
3421 &match_pos)) break; | 3420 &match_pos)) break; |
3422 } | 3421 } |
3423 } else { | 3422 } else { |
3424 Vector<const uc16> subject_vector = subject->ToUC16Vector(); | 3423 Vector<const uc16> subject_vector = subject_content.ToUC16Vector(); |
3425 if (pattern->IsAsciiRepresentation()) { | 3424 if (pattern_content.IsAscii()) { |
3426 if (SearchStringMultiple(isolate, | 3425 if (SearchStringMultiple(isolate, |
3427 subject_vector, | 3426 subject_vector, |
3428 pattern->ToAsciiVector(), | 3427 pattern_content.ToAsciiVector(), |
3429 *pattern, | 3428 *pattern, |
3430 builder, | 3429 builder, |
3431 &match_pos)) break; | 3430 &match_pos)) break; |
3432 } else { | 3431 } else { |
3433 if (SearchStringMultiple(isolate, | 3432 if (SearchStringMultiple(isolate, |
3434 subject_vector, | 3433 subject_vector, |
3435 pattern->ToUC16Vector(), | 3434 pattern_content.ToUC16Vector(), |
3436 *pattern, | 3435 *pattern, |
3437 builder, | 3436 builder, |
3438 &match_pos)) break; | 3437 &match_pos)) break; |
3439 } | 3438 } |
3440 } | 3439 } |
3441 } | 3440 } |
3442 | 3441 |
3443 if (match_pos >= 0) { | 3442 if (match_pos >= 0) { |
3444 SetLastMatchInfoNoCaptures(subject, | 3443 SetLastMatchInfoNoCaptures(subject, |
3445 last_match_info, | 3444 last_match_info, |
(...skipping 1967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5413 CONVERT_CHECKED(String, str, args[0]); | 5412 CONVERT_CHECKED(String, str, args[0]); |
5414 if (!str->IsFlat()) { | 5413 if (!str->IsFlat()) { |
5415 MaybeObject* try_flatten = str->TryFlatten(); | 5414 MaybeObject* try_flatten = str->TryFlatten(); |
5416 Object* flat; | 5415 Object* flat; |
5417 if (!try_flatten->ToObject(&flat)) { | 5416 if (!try_flatten->ToObject(&flat)) { |
5418 return try_flatten; | 5417 return try_flatten; |
5419 } | 5418 } |
5420 str = String::cast(flat); | 5419 str = String::cast(flat); |
5421 ASSERT(str->IsFlat()); | 5420 ASSERT(str->IsFlat()); |
5422 } | 5421 } |
5423 if (str->IsTwoByteRepresentation()) { | 5422 String::FlatContent flat = str->GetFlatContent(); |
| 5423 ASSERT(flat.IsFlat()); |
| 5424 if (flat.IsTwoByte()) { |
5424 return QuoteJsonString<uc16, SeqTwoByteString, false>(isolate, | 5425 return QuoteJsonString<uc16, SeqTwoByteString, false>(isolate, |
5425 str->ToUC16Vector()); | 5426 flat.ToUC16Vector()); |
5426 } else { | 5427 } else { |
5427 return QuoteJsonString<char, SeqAsciiString, false>(isolate, | 5428 return QuoteJsonString<char, SeqAsciiString, false>(isolate, |
5428 str->ToAsciiVector()); | 5429 flat.ToAsciiVector()); |
5429 } | 5430 } |
5430 } | 5431 } |
5431 | 5432 |
5432 | 5433 |
5433 RUNTIME_FUNCTION(MaybeObject*, Runtime_QuoteJSONStringComma) { | 5434 RUNTIME_FUNCTION(MaybeObject*, Runtime_QuoteJSONStringComma) { |
5434 NoHandleAllocation ha; | 5435 NoHandleAllocation ha; |
5435 CONVERT_CHECKED(String, str, args[0]); | 5436 CONVERT_CHECKED(String, str, args[0]); |
5436 if (!str->IsFlat()) { | 5437 if (!str->IsFlat()) { |
5437 MaybeObject* try_flatten = str->TryFlatten(); | 5438 MaybeObject* try_flatten = str->TryFlatten(); |
5438 Object* flat; | 5439 Object* flat; |
5439 if (!try_flatten->ToObject(&flat)) { | 5440 if (!try_flatten->ToObject(&flat)) { |
5440 return try_flatten; | 5441 return try_flatten; |
5441 } | 5442 } |
5442 str = String::cast(flat); | 5443 str = String::cast(flat); |
5443 ASSERT(str->IsFlat()); | 5444 ASSERT(str->IsFlat()); |
5444 } | 5445 } |
5445 if (str->IsTwoByteRepresentation()) { | 5446 String::FlatContent flat = str->GetFlatContent(); |
| 5447 if (flat.IsTwoByte()) { |
5446 return QuoteJsonString<uc16, SeqTwoByteString, true>(isolate, | 5448 return QuoteJsonString<uc16, SeqTwoByteString, true>(isolate, |
5447 str->ToUC16Vector()); | 5449 flat.ToUC16Vector()); |
5448 } else { | 5450 } else { |
5449 return QuoteJsonString<char, SeqAsciiString, true>(isolate, | 5451 return QuoteJsonString<char, SeqAsciiString, true>(isolate, |
5450 str->ToAsciiVector()); | 5452 flat.ToAsciiVector()); |
5451 } | 5453 } |
5452 } | 5454 } |
5453 | 5455 |
5454 | 5456 |
5455 template <typename Char, typename StringType> | 5457 template <typename Char, typename StringType> |
5456 static MaybeObject* QuoteJsonStringArray(Isolate* isolate, | 5458 static MaybeObject* QuoteJsonStringArray(Isolate* isolate, |
5457 FixedArray* array, | 5459 FixedArray* array, |
5458 int worst_case_length) { | 5460 int worst_case_length) { |
5459 int length = array->length(); | 5461 int length = array->length(); |
5460 | 5462 |
(...skipping 14 matching lines...) Expand all Loading... |
5475 StringType* new_string = StringType::cast(new_object); | 5477 StringType* new_string = StringType::cast(new_object); |
5476 ASSERT(isolate->heap()->new_space()->Contains(new_string)); | 5478 ASSERT(isolate->heap()->new_space()->Contains(new_string)); |
5477 | 5479 |
5478 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); | 5480 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
5479 Char* write_cursor = reinterpret_cast<Char*>( | 5481 Char* write_cursor = reinterpret_cast<Char*>( |
5480 new_string->address() + SeqAsciiString::kHeaderSize); | 5482 new_string->address() + SeqAsciiString::kHeaderSize); |
5481 *(write_cursor++) = '['; | 5483 *(write_cursor++) = '['; |
5482 for (int i = 0; i < length; i++) { | 5484 for (int i = 0; i < length; i++) { |
5483 if (i != 0) *(write_cursor++) = ','; | 5485 if (i != 0) *(write_cursor++) = ','; |
5484 String* str = String::cast(array->get(i)); | 5486 String* str = String::cast(array->get(i)); |
5485 if (str->IsTwoByteRepresentation()) { | 5487 String::FlatContent content = str->GetFlatContent(); |
| 5488 ASSERT(content.IsFlat()); |
| 5489 if (content.IsTwoByte()) { |
5486 write_cursor = WriteQuoteJsonString<Char, uc16>(isolate, | 5490 write_cursor = WriteQuoteJsonString<Char, uc16>(isolate, |
5487 write_cursor, | 5491 write_cursor, |
5488 str->ToUC16Vector()); | 5492 content.ToUC16Vector()); |
5489 } else { | 5493 } else { |
5490 write_cursor = WriteQuoteJsonString<Char, char>(isolate, | 5494 write_cursor = WriteQuoteJsonString<Char, char>(isolate, |
5491 write_cursor, | 5495 write_cursor, |
5492 str->ToAsciiVector()); | 5496 content.ToAsciiVector()); |
5493 } | 5497 } |
5494 } | 5498 } |
5495 *(write_cursor++) = ']'; | 5499 *(write_cursor++) = ']'; |
5496 | 5500 |
5497 int final_length = static_cast<int>( | 5501 int final_length = static_cast<int>( |
5498 write_cursor - reinterpret_cast<Char*>( | 5502 write_cursor - reinterpret_cast<Char*>( |
5499 new_string->address() + SeqAsciiString::kHeaderSize)); | 5503 new_string->address() + SeqAsciiString::kHeaderSize)); |
5500 isolate->heap()->new_space()-> | 5504 isolate->heap()->new_space()-> |
5501 template ShrinkStringAtAllocationBoundary<StringType>( | 5505 template ShrinkStringAtAllocationBoundary<StringType>( |
5502 new_string, final_length); | 5506 new_string, final_length); |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5962 ZoneScope scope(isolate, DELETE_ON_EXIT); | 5966 ZoneScope scope(isolate, DELETE_ON_EXIT); |
5963 | 5967 |
5964 // Find (up to limit) indices of separator and end-of-string in subject | 5968 // Find (up to limit) indices of separator and end-of-string in subject |
5965 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); | 5969 int initial_capacity = Min<uint32_t>(kMaxInitialListCapacity, limit); |
5966 ZoneList<int> indices(initial_capacity); | 5970 ZoneList<int> indices(initial_capacity); |
5967 if (!pattern->IsFlat()) FlattenString(pattern); | 5971 if (!pattern->IsFlat()) FlattenString(pattern); |
5968 | 5972 |
5969 // No allocation block. | 5973 // No allocation block. |
5970 { | 5974 { |
5971 AssertNoAllocation nogc; | 5975 AssertNoAllocation nogc; |
5972 if (subject->IsAsciiRepresentation()) { | 5976 String::FlatContent subject_content = subject->GetFlatContent(); |
5973 Vector<const char> subject_vector = subject->ToAsciiVector(); | 5977 String::FlatContent pattern_content = pattern->GetFlatContent(); |
5974 if (pattern->IsAsciiRepresentation()) { | 5978 ASSERT(subject_content.IsFlat()); |
5975 Vector<const char> pattern_vector = pattern->ToAsciiVector(); | 5979 ASSERT(pattern_content.IsFlat()); |
| 5980 if (subject_content.IsAscii()) { |
| 5981 Vector<const char> subject_vector = subject_content.ToAsciiVector(); |
| 5982 if (pattern_content.IsAscii()) { |
| 5983 Vector<const char> pattern_vector = pattern_content.ToAsciiVector(); |
5976 if (pattern_vector.length() == 1) { | 5984 if (pattern_vector.length() == 1) { |
5977 FindAsciiStringIndices(subject_vector, | 5985 FindAsciiStringIndices(subject_vector, |
5978 pattern_vector[0], | 5986 pattern_vector[0], |
5979 &indices, | 5987 &indices, |
5980 limit); | 5988 limit); |
5981 } else { | 5989 } else { |
5982 FindStringIndices(isolate, | 5990 FindStringIndices(isolate, |
5983 subject_vector, | 5991 subject_vector, |
5984 pattern_vector, | 5992 pattern_vector, |
5985 &indices, | 5993 &indices, |
5986 limit); | 5994 limit); |
5987 } | 5995 } |
5988 } else { | 5996 } else { |
5989 FindStringIndices(isolate, | 5997 FindStringIndices(isolate, |
5990 subject_vector, | 5998 subject_vector, |
5991 pattern->ToUC16Vector(), | 5999 pattern_content.ToUC16Vector(), |
5992 &indices, | 6000 &indices, |
5993 limit); | 6001 limit); |
5994 } | 6002 } |
5995 } else { | 6003 } else { |
5996 Vector<const uc16> subject_vector = subject->ToUC16Vector(); | 6004 Vector<const uc16> subject_vector = subject_content.ToUC16Vector(); |
5997 if (pattern->IsAsciiRepresentation()) { | 6005 if (pattern->IsAsciiRepresentation()) { |
5998 FindStringIndices(isolate, | 6006 FindStringIndices(isolate, |
5999 subject_vector, | 6007 subject_vector, |
6000 pattern->ToAsciiVector(), | 6008 pattern_content.ToAsciiVector(), |
6001 &indices, | 6009 &indices, |
6002 limit); | 6010 limit); |
6003 } else { | 6011 } else { |
6004 FindStringIndices(isolate, | 6012 FindStringIndices(isolate, |
6005 subject_vector, | 6013 subject_vector, |
6006 pattern->ToUC16Vector(), | 6014 pattern_content.ToUC16Vector(), |
6007 &indices, | 6015 &indices, |
6008 limit); | 6016 limit); |
6009 } | 6017 } |
6010 } | 6018 } |
6011 } | 6019 } |
6012 | 6020 |
6013 if (static_cast<uint32_t>(indices.length()) < limit) { | 6021 if (static_cast<uint32_t>(indices.length()) < limit) { |
6014 indices.Add(subject_length); | 6022 indices.Add(subject_length); |
6015 } | 6023 } |
6016 | 6024 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6082 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToArray) { | 6090 RUNTIME_FUNCTION(MaybeObject*, Runtime_StringToArray) { |
6083 HandleScope scope(isolate); | 6091 HandleScope scope(isolate); |
6084 ASSERT(args.length() == 2); | 6092 ASSERT(args.length() == 2); |
6085 CONVERT_ARG_CHECKED(String, s, 0); | 6093 CONVERT_ARG_CHECKED(String, s, 0); |
6086 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); | 6094 CONVERT_NUMBER_CHECKED(uint32_t, limit, Uint32, args[1]); |
6087 | 6095 |
6088 s->TryFlatten(); | 6096 s->TryFlatten(); |
6089 const int length = static_cast<int>(Min<uint32_t>(s->length(), limit)); | 6097 const int length = static_cast<int>(Min<uint32_t>(s->length(), limit)); |
6090 | 6098 |
6091 Handle<FixedArray> elements; | 6099 Handle<FixedArray> elements; |
6092 if (s->IsFlat() && s->IsAsciiRepresentation()) { | 6100 String::FlatContent content = s->GetFlatContent(); |
| 6101 if (content.IsAscii()) { |
6093 Object* obj; | 6102 Object* obj; |
6094 { MaybeObject* maybe_obj = | 6103 { MaybeObject* maybe_obj = |
6095 isolate->heap()->AllocateUninitializedFixedArray(length); | 6104 isolate->heap()->AllocateUninitializedFixedArray(length); |
6096 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 6105 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
6097 } | 6106 } |
6098 elements = Handle<FixedArray>(FixedArray::cast(obj), isolate); | 6107 elements = Handle<FixedArray>(FixedArray::cast(obj), isolate); |
6099 | 6108 |
6100 Vector<const char> chars = s->ToAsciiVector(); | 6109 Vector<const char> chars = content.ToAsciiVector(); |
6101 // Note, this will initialize all elements (not only the prefix) | 6110 // Note, this will initialize all elements (not only the prefix) |
6102 // to prevent GC from seeing partially initialized array. | 6111 // to prevent GC from seeing partially initialized array. |
6103 int num_copied_from_cache = CopyCachedAsciiCharsToArray(isolate->heap(), | 6112 int num_copied_from_cache = CopyCachedAsciiCharsToArray(isolate->heap(), |
6104 chars.start(), | 6113 chars.start(), |
6105 *elements, | 6114 *elements, |
6106 length); | 6115 length); |
6107 | 6116 |
6108 for (int i = num_copied_from_cache; i < length; ++i) { | 6117 for (int i = num_copied_from_cache; i < length; ++i) { |
6109 Handle<Object> str = LookupSingleCharacterStringFromCode(chars[i]); | 6118 Handle<Object> str = LookupSingleCharacterStringFromCode(chars[i]); |
6110 elements->set(i, *str); | 6119 elements->set(i, *str); |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6918 ASSERT(y->IsFlat()); | 6927 ASSERT(y->IsFlat()); |
6919 Object* equal_prefix_result = Smi::FromInt(EQUAL); | 6928 Object* equal_prefix_result = Smi::FromInt(EQUAL); |
6920 int prefix_length = x->length(); | 6929 int prefix_length = x->length(); |
6921 if (y->length() < prefix_length) { | 6930 if (y->length() < prefix_length) { |
6922 prefix_length = y->length(); | 6931 prefix_length = y->length(); |
6923 equal_prefix_result = Smi::FromInt(GREATER); | 6932 equal_prefix_result = Smi::FromInt(GREATER); |
6924 } else if (y->length() > prefix_length) { | 6933 } else if (y->length() > prefix_length) { |
6925 equal_prefix_result = Smi::FromInt(LESS); | 6934 equal_prefix_result = Smi::FromInt(LESS); |
6926 } | 6935 } |
6927 int r; | 6936 int r; |
6928 if (x->IsAsciiRepresentation()) { | 6937 String::FlatContent x_content = x->GetFlatContent(); |
6929 Vector<const char> x_chars = x->ToAsciiVector(); | 6938 String::FlatContent y_content = y->GetFlatContent(); |
6930 if (y->IsAsciiRepresentation()) { | 6939 if (x_content.IsAscii()) { |
6931 Vector<const char> y_chars = y->ToAsciiVector(); | 6940 Vector<const char> x_chars = x_content.ToAsciiVector(); |
| 6941 if (y_content.IsAscii()) { |
| 6942 Vector<const char> y_chars = y_content.ToAsciiVector(); |
6932 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); | 6943 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); |
6933 } else { | 6944 } else { |
6934 Vector<const uc16> y_chars = y->ToUC16Vector(); | 6945 Vector<const uc16> y_chars = y_content.ToUC16Vector(); |
6935 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); | 6946 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); |
6936 } | 6947 } |
6937 } else { | 6948 } else { |
6938 Vector<const uc16> x_chars = x->ToUC16Vector(); | 6949 Vector<const uc16> x_chars = x_content.ToUC16Vector(); |
6939 if (y->IsAsciiRepresentation()) { | 6950 if (y_content.IsAscii()) { |
6940 Vector<const char> y_chars = y->ToAsciiVector(); | 6951 Vector<const char> y_chars = y_content.ToAsciiVector(); |
6941 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); | 6952 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); |
6942 } else { | 6953 } else { |
6943 Vector<const uc16> y_chars = y->ToUC16Vector(); | 6954 Vector<const uc16> y_chars = y_content.ToUC16Vector(); |
6944 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); | 6955 r = CompareChars(x_chars.start(), y_chars.start(), prefix_length); |
6945 } | 6956 } |
6946 } | 6957 } |
6947 Object* result; | 6958 Object* result; |
6948 if (r == 0) { | 6959 if (r == 0) { |
6949 result = equal_prefix_result; | 6960 result = equal_prefix_result; |
6950 } else { | 6961 } else { |
6951 result = (r < 0) ? Smi::FromInt(LESS) : Smi::FromInt(GREATER); | 6962 result = (r < 0) ? Smi::FromInt(LESS) : Smi::FromInt(GREATER); |
6952 } | 6963 } |
6953 ASSERT(result == | 6964 ASSERT(result == |
(...skipping 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8814 FlattenString(str); | 8825 FlattenString(str); |
8815 | 8826 |
8816 CONVERT_ARG_CHECKED(JSArray, output, 1); | 8827 CONVERT_ARG_CHECKED(JSArray, output, 1); |
8817 RUNTIME_ASSERT(output->HasFastElements()); | 8828 RUNTIME_ASSERT(output->HasFastElements()); |
8818 | 8829 |
8819 AssertNoAllocation no_allocation; | 8830 AssertNoAllocation no_allocation; |
8820 | 8831 |
8821 FixedArray* output_array = FixedArray::cast(output->elements()); | 8832 FixedArray* output_array = FixedArray::cast(output->elements()); |
8822 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE); | 8833 RUNTIME_ASSERT(output_array->length() >= DateParser::OUTPUT_SIZE); |
8823 bool result; | 8834 bool result; |
8824 if (str->IsAsciiRepresentation()) { | 8835 String::FlatContent str_content = str->GetFlatContent(); |
8825 result = DateParser::Parse(str->ToAsciiVector(), | 8836 if (str_content.IsAscii()) { |
| 8837 result = DateParser::Parse(str_content.ToAsciiVector(), |
8826 output_array, | 8838 output_array, |
8827 isolate->unicode_cache()); | 8839 isolate->unicode_cache()); |
8828 } else { | 8840 } else { |
8829 ASSERT(str->IsTwoByteRepresentation()); | 8841 ASSERT(str_content.IsTwoByte()); |
8830 result = DateParser::Parse(str->ToUC16Vector(), | 8842 result = DateParser::Parse(str_content.ToUC16Vector(), |
8831 output_array, | 8843 output_array, |
8832 isolate->unicode_cache()); | 8844 isolate->unicode_cache()); |
8833 } | 8845 } |
8834 | 8846 |
8835 if (result) { | 8847 if (result) { |
8836 return *output; | 8848 return *output; |
8837 } else { | 8849 } else { |
8838 return isolate->heap()->null_value(); | 8850 return isolate->heap()->null_value(); |
8839 } | 8851 } |
8840 } | 8852 } |
(...skipping 3959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12800 Handle<JSArray> result = factory->NewJSArrayWithElements(elements); | 12812 Handle<JSArray> result = factory->NewJSArrayWithElements(elements); |
12801 return *result; | 12813 return *result; |
12802 } | 12814 } |
12803 #endif | 12815 #endif |
12804 | 12816 |
12805 | 12817 |
12806 RUNTIME_FUNCTION(MaybeObject*, Runtime_Log) { | 12818 RUNTIME_FUNCTION(MaybeObject*, Runtime_Log) { |
12807 ASSERT(args.length() == 2); | 12819 ASSERT(args.length() == 2); |
12808 CONVERT_CHECKED(String, format, args[0]); | 12820 CONVERT_CHECKED(String, format, args[0]); |
12809 CONVERT_CHECKED(JSArray, elms, args[1]); | 12821 CONVERT_CHECKED(JSArray, elms, args[1]); |
12810 Vector<const char> chars = format->ToAsciiVector(); | 12822 String::FlatContent format_content = format->GetFlatContent(); |
| 12823 RUNTIME_ASSERT(format_content.IsAscii()); |
| 12824 Vector<const char> chars = format_content.ToAsciiVector(); |
12811 LOGGER->LogRuntime(chars, elms); | 12825 LOGGER->LogRuntime(chars, elms); |
12812 return isolate->heap()->undefined_value(); | 12826 return isolate->heap()->undefined_value(); |
12813 } | 12827 } |
12814 | 12828 |
12815 | 12829 |
12816 RUNTIME_FUNCTION(MaybeObject*, Runtime_IS_VAR) { | 12830 RUNTIME_FUNCTION(MaybeObject*, Runtime_IS_VAR) { |
12817 UNREACHABLE(); // implemented as macro in the parser | 12831 UNREACHABLE(); // implemented as macro in the parser |
12818 return NULL; | 12832 return NULL; |
12819 } | 12833 } |
12820 | 12834 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12914 } else { | 12928 } else { |
12915 // Handle last resort GC and make sure to allow future allocations | 12929 // Handle last resort GC and make sure to allow future allocations |
12916 // to grow the heap without causing GCs (if possible). | 12930 // to grow the heap without causing GCs (if possible). |
12917 isolate->counters()->gc_last_resort_from_js()->Increment(); | 12931 isolate->counters()->gc_last_resort_from_js()->Increment(); |
12918 isolate->heap()->CollectAllGarbage(false); | 12932 isolate->heap()->CollectAllGarbage(false); |
12919 } | 12933 } |
12920 } | 12934 } |
12921 | 12935 |
12922 | 12936 |
12923 } } // namespace v8::internal | 12937 } } // namespace v8::internal |
OLD | NEW |