Chromium Code Reviews| 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 2643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2654 // dictionary. Check whether we already have the string in the symbol | 2654 // dictionary. Check whether we already have the string in the symbol |
| 2655 // table to prevent creation of many unneccesary strings. | 2655 // table to prevent creation of many unneccesary strings. |
| 2656 unsigned c1 = buffer->Get(start); | 2656 unsigned c1 = buffer->Get(start); |
| 2657 unsigned c2 = buffer->Get(start + 1); | 2657 unsigned c2 = buffer->Get(start + 1); |
| 2658 return MakeOrFindTwoCharacterString(this, c1, c2); | 2658 return MakeOrFindTwoCharacterString(this, c1, c2); |
| 2659 } | 2659 } |
| 2660 | 2660 |
| 2661 // Make an attempt to flatten the buffer to reduce access time. | 2661 // Make an attempt to flatten the buffer to reduce access time. |
| 2662 buffer = buffer->TryFlattenGetString(); | 2662 buffer = buffer->TryFlattenGetString(); |
| 2663 | 2663 |
| 2664 // TODO(1626): For now slicing external strings is not supported. However, | |
| 2665 // a flat cons string can have an external string as first part in some cases. | |
| 2666 // Therefore we have to single out this case as well. | |
| 2667 if (!FLAG_string_slices || | 2664 if (!FLAG_string_slices || |
| 2668 (buffer->IsConsString() && | 2665 !buffer->IsFlat() || |
| 2669 (!buffer->IsFlat() || | |
| 2670 !ConsString::cast(buffer)->first()->IsSeqString())) || | |
| 2671 buffer->IsExternalString() || | |
| 2672 length < SlicedString::kMinLength || | 2666 length < SlicedString::kMinLength || |
| 2673 pretenure == TENURED) { | 2667 pretenure == TENURED) { |
| 2674 Object* result; | 2668 Object* result; |
| 2675 { MaybeObject* maybe_result = buffer->IsAsciiRepresentation() | 2669 // The string encoding of the string might be ascii, while the underlying |
|
Vitaly Repeshko
2011/09/13 18:20:25
Let's just replace this with
"WriteToFlat takes ca
| |
| 2676 ? AllocateRawAsciiString(length, pretenure) | 2670 // string is actually a twobyte. The content must be ascii though, |
| 2677 : AllocateRawTwoByteString(length, pretenure); | 2671 // therefore this is a good opportunity to go back to ascii encoding. |
| 2672 // WriteToFlat takes care of twobyte to ascii conversion. | |
| 2673 bool is_ascii = buffer->IsAsciiRepresentation(); | |
| 2674 { MaybeObject* maybe_result = is_ascii | |
| 2675 ? AllocateRawAsciiString(length, pretenure) | |
| 2676 : AllocateRawTwoByteString(length, pretenure); | |
| 2678 if (!maybe_result->ToObject(&result)) return maybe_result; | 2677 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2679 } | 2678 } |
| 2680 String* string_result = String::cast(result); | 2679 String* string_result = String::cast(result); |
| 2681 // Copy the characters into the new object. | 2680 // Copy the characters into the new object. |
| 2682 if (buffer->IsAsciiRepresentation()) { | 2681 if (is_ascii) { |
| 2683 ASSERT(string_result->IsAsciiRepresentation()); | 2682 ASSERT(string_result->IsAsciiRepresentation()); |
| 2684 char* dest = SeqAsciiString::cast(string_result)->GetChars(); | 2683 char* dest = SeqAsciiString::cast(string_result)->GetChars(); |
| 2685 String::WriteToFlat(buffer, dest, start, end); | 2684 String::WriteToFlat(buffer, dest, start, end); |
| 2686 } else { | 2685 } else { |
| 2687 ASSERT(string_result->IsTwoByteRepresentation()); | 2686 ASSERT(string_result->IsTwoByteRepresentation()); |
| 2688 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); | 2687 uc16* dest = SeqTwoByteString::cast(string_result)->GetChars(); |
| 2689 String::WriteToFlat(buffer, dest, start, end); | 2688 String::WriteToFlat(buffer, dest, start, end); |
| 2690 } | 2689 } |
| 2691 return result; | 2690 return result; |
| 2692 } | 2691 } |
| 2693 | 2692 |
| 2694 ASSERT(buffer->IsFlat()); | 2693 ASSERT(buffer->IsFlat()); |
| 2695 ASSERT(!buffer->IsExternalString()); | |
| 2696 #if DEBUG | 2694 #if DEBUG |
| 2697 buffer->StringVerify(); | 2695 buffer->StringVerify(); |
| 2698 #endif | 2696 #endif |
| 2699 | 2697 |
| 2700 Object* result; | 2698 Object* result; |
| 2699 // The string encoding tag in the newly created slice does not really matter. | |
|
Vitaly Repeshko
2011/09/13 18:20:25
"When slicing an indirect string we use its encodi
| |
| 2700 // Therefore we do not further check the encoding of the underlying string. | |
| 2701 { Map* map = buffer->IsAsciiRepresentation() | 2701 { Map* map = buffer->IsAsciiRepresentation() |
| 2702 ? sliced_ascii_string_map() | 2702 ? sliced_ascii_string_map() |
| 2703 : sliced_string_map(); | 2703 : sliced_string_map(); |
| 2704 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); | 2704 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
| 2705 if (!maybe_result->ToObject(&result)) return maybe_result; | 2705 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2706 } | 2706 } |
| 2707 | 2707 |
| 2708 AssertNoAllocation no_gc; | 2708 AssertNoAllocation no_gc; |
| 2709 SlicedString* sliced_string = SlicedString::cast(result); | 2709 SlicedString* sliced_string = SlicedString::cast(result); |
| 2710 sliced_string->set_length(length); | 2710 sliced_string->set_length(length); |
| 2711 sliced_string->set_hash_field(String::kEmptyHashField); | 2711 sliced_string->set_hash_field(String::kEmptyHashField); |
| 2712 if (buffer->IsConsString()) { | 2712 if (buffer->IsConsString()) { |
| 2713 ConsString* cons = ConsString::cast(buffer); | 2713 ConsString* cons = ConsString::cast(buffer); |
| 2714 ASSERT(cons->second()->length() == 0); | 2714 ASSERT(cons->second()->length() == 0); |
| 2715 sliced_string->set_parent(cons->first()); | 2715 sliced_string->set_parent(cons->first()); |
| 2716 sliced_string->set_offset(start); | 2716 sliced_string->set_offset(start); |
| 2717 } else if (buffer->IsSlicedString()) { | 2717 } else if (buffer->IsSlicedString()) { |
| 2718 // Prevent nesting sliced strings. | 2718 // Prevent nesting sliced strings. |
| 2719 SlicedString* parent_slice = SlicedString::cast(buffer); | 2719 SlicedString* parent_slice = SlicedString::cast(buffer); |
| 2720 sliced_string->set_parent(parent_slice->parent()); | 2720 sliced_string->set_parent(parent_slice->parent()); |
| 2721 sliced_string->set_offset(start + parent_slice->offset()); | 2721 sliced_string->set_offset(start + parent_slice->offset()); |
| 2722 } else { | 2722 } else { |
| 2723 sliced_string->set_parent(buffer); | 2723 sliced_string->set_parent(buffer); |
| 2724 sliced_string->set_offset(start); | 2724 sliced_string->set_offset(start); |
| 2725 } | 2725 } |
| 2726 ASSERT(sliced_string->parent()->IsSeqString()); | 2726 ASSERT(sliced_string->parent()->IsSeqString() || |
| 2727 sliced_string->parent()->IsExternalString()); | |
| 2727 return result; | 2728 return result; |
| 2728 } | 2729 } |
| 2729 | 2730 |
| 2730 | 2731 |
| 2731 MaybeObject* Heap::AllocateExternalStringFromAscii( | 2732 MaybeObject* Heap::AllocateExternalStringFromAscii( |
| 2732 ExternalAsciiString::Resource* resource) { | 2733 ExternalAsciiString::Resource* resource) { |
| 2733 size_t length = resource->length(); | 2734 size_t length = resource->length(); |
| 2734 if (length > static_cast<size_t>(String::kMaxLength)) { | 2735 if (length > static_cast<size_t>(String::kMaxLength)) { |
| 2735 isolate()->context()->mark_out_of_memory(); | 2736 isolate()->context()->mark_out_of_memory(); |
| 2736 return Failure::OutOfMemoryException(); | 2737 return Failure::OutOfMemoryException(); |
| (...skipping 3409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6146 } | 6147 } |
| 6147 | 6148 |
| 6148 | 6149 |
| 6149 void ExternalStringTable::TearDown() { | 6150 void ExternalStringTable::TearDown() { |
| 6150 new_space_strings_.Free(); | 6151 new_space_strings_.Free(); |
| 6151 old_space_strings_.Free(); | 6152 old_space_strings_.Free(); |
| 6152 } | 6153 } |
| 6153 | 6154 |
| 6154 | 6155 |
| 6155 } } // namespace v8::internal | 6156 } } // namespace v8::internal |
| OLD | NEW |