OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 if (cs->second()->length() == 0) { | 875 if (cs->second()->length() == 0) { |
876 return cs->first(); | 876 return cs->first(); |
877 } | 877 } |
878 // There's little point in putting the flat string in new space if the | 878 // There's little point in putting the flat string in new space if the |
879 // cons string is in old space. It can never get GCed until there is | 879 // cons string is in old space. It can never get GCed until there is |
880 // an old space GC. | 880 // an old space GC. |
881 PretenureFlag tenure = heap->InNewSpace(this) ? pretenure : TENURED; | 881 PretenureFlag tenure = heap->InNewSpace(this) ? pretenure : TENURED; |
882 int len = length(); | 882 int len = length(); |
883 Object* object; | 883 Object* object; |
884 String* result; | 884 String* result; |
885 if (IsAsciiRepresentation()) { | 885 if (IsOneByteRepresentation()) { |
886 { MaybeObject* maybe_object = heap->AllocateRawAsciiString(len, tenure); | 886 { MaybeObject* maybe_object = |
| 887 heap->AllocateRawOneByteString(len, tenure); |
887 if (!maybe_object->ToObject(&object)) return maybe_object; | 888 if (!maybe_object->ToObject(&object)) return maybe_object; |
888 } | 889 } |
889 result = String::cast(object); | 890 result = String::cast(object); |
890 String* first = cs->first(); | 891 String* first = cs->first(); |
891 int first_length = first->length(); | 892 int first_length = first->length(); |
892 char* dest = SeqOneByteString::cast(result)->GetChars(); | 893 char* dest = SeqOneByteString::cast(result)->GetChars(); |
893 WriteToFlat(first, dest, 0, first_length); | 894 WriteToFlat(first, dest, 0, first_length); |
894 String* second = cs->second(); | 895 String* second = cs->second(); |
895 WriteToFlat(second, | 896 WriteToFlat(second, |
896 dest + first_length, | 897 dest + first_length, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 ASSERT(memcmp(smart_chars.start(), | 936 ASSERT(memcmp(smart_chars.start(), |
936 resource->data(), | 937 resource->data(), |
937 resource->length() * sizeof(smart_chars[0])) == 0); | 938 resource->length() * sizeof(smart_chars[0])) == 0); |
938 } | 939 } |
939 #endif // DEBUG | 940 #endif // DEBUG |
940 Heap* heap = GetHeap(); | 941 Heap* heap = GetHeap(); |
941 int size = this->Size(); // Byte size of the original string. | 942 int size = this->Size(); // Byte size of the original string. |
942 if (size < ExternalString::kShortSize) { | 943 if (size < ExternalString::kShortSize) { |
943 return false; | 944 return false; |
944 } | 945 } |
945 bool is_ascii = this->IsAsciiRepresentation(); | 946 bool is_ascii = this->IsOneByteRepresentation(); |
946 bool is_symbol = this->IsSymbol(); | 947 bool is_symbol = this->IsSymbol(); |
947 | 948 |
948 // Morph the object to an external string by adjusting the map and | 949 // Morph the object to an external string by adjusting the map and |
949 // reinitializing the fields. | 950 // reinitializing the fields. |
950 if (size >= ExternalString::kSize) { | 951 if (size >= ExternalString::kSize) { |
951 this->set_map_no_write_barrier( | 952 this->set_map_no_write_barrier( |
952 is_symbol | 953 is_symbol |
953 ? (is_ascii ? heap->external_symbol_with_ascii_data_map() | 954 ? (is_ascii ? heap->external_symbol_with_ascii_data_map() |
954 : heap->external_symbol_map()) | 955 : heap->external_symbol_map()) |
955 : (is_ascii ? heap->external_string_with_ascii_data_map() | 956 : (is_ascii ? heap->external_string_with_ascii_data_map() |
(...skipping 5636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6592 return ToCString(allow_nulls, robust_flag, 0, -1, length_return); | 6593 return ToCString(allow_nulls, robust_flag, 0, -1, length_return); |
6593 } | 6594 } |
6594 | 6595 |
6595 | 6596 |
6596 const uc16* String::GetTwoByteData() { | 6597 const uc16* String::GetTwoByteData() { |
6597 return GetTwoByteData(0); | 6598 return GetTwoByteData(0); |
6598 } | 6599 } |
6599 | 6600 |
6600 | 6601 |
6601 const uc16* String::GetTwoByteData(unsigned start) { | 6602 const uc16* String::GetTwoByteData(unsigned start) { |
6602 ASSERT(!IsAsciiRepresentationUnderneath()); | 6603 ASSERT(!IsOneByteRepresentationUnderneath()); |
6603 switch (StringShape(this).representation_tag()) { | 6604 switch (StringShape(this).representation_tag()) { |
6604 case kSeqStringTag: | 6605 case kSeqStringTag: |
6605 return SeqTwoByteString::cast(this)->SeqTwoByteStringGetData(start); | 6606 return SeqTwoByteString::cast(this)->SeqTwoByteStringGetData(start); |
6606 case kExternalStringTag: | 6607 case kExternalStringTag: |
6607 return ExternalTwoByteString::cast(this)-> | 6608 return ExternalTwoByteString::cast(this)-> |
6608 ExternalTwoByteStringGetData(start); | 6609 ExternalTwoByteStringGetData(start); |
6609 case kSlicedStringTag: { | 6610 case kSlicedStringTag: { |
6610 SlicedString* slice = SlicedString::cast(this); | 6611 SlicedString* slice = SlicedString::cast(this); |
6611 return slice->parent()->GetTwoByteData(start + slice->offset()); | 6612 return slice->parent()->GetTwoByteData(start + slice->offset()); |
6612 } | 6613 } |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6844 ReadBlockBuffer* rbb, | 6845 ReadBlockBuffer* rbb, |
6845 unsigned* offset_ptr, | 6846 unsigned* offset_ptr, |
6846 unsigned max_chars) { | 6847 unsigned max_chars) { |
6847 ASSERT(*offset_ptr <= static_cast<unsigned>(input->length())); | 6848 ASSERT(*offset_ptr <= static_cast<unsigned>(input->length())); |
6848 if (max_chars == 0) { | 6849 if (max_chars == 0) { |
6849 rbb->remaining = 0; | 6850 rbb->remaining = 0; |
6850 return NULL; | 6851 return NULL; |
6851 } | 6852 } |
6852 switch (StringShape(input).representation_tag()) { | 6853 switch (StringShape(input).representation_tag()) { |
6853 case kSeqStringTag: | 6854 case kSeqStringTag: |
6854 if (input->IsAsciiRepresentation()) { | 6855 if (input->IsOneByteRepresentation()) { |
6855 SeqOneByteString* str = SeqOneByteString::cast(input); | 6856 SeqOneByteString* str = SeqOneByteString::cast(input); |
6856 return str->SeqOneByteStringReadBlock(&rbb->remaining, | 6857 return str->SeqOneByteStringReadBlock(&rbb->remaining, |
6857 offset_ptr, | 6858 offset_ptr, |
6858 max_chars); | 6859 max_chars); |
6859 } else { | 6860 } else { |
6860 SeqTwoByteString* str = SeqTwoByteString::cast(input); | 6861 SeqTwoByteString* str = SeqTwoByteString::cast(input); |
6861 str->SeqTwoByteStringReadBlockIntoBuffer(rbb, | 6862 str->SeqTwoByteStringReadBlockIntoBuffer(rbb, |
6862 offset_ptr, | 6863 offset_ptr, |
6863 max_chars); | 6864 max_chars); |
6864 return rbb->util_buffer; | 6865 return rbb->util_buffer; |
6865 } | 6866 } |
6866 case kConsStringTag: | 6867 case kConsStringTag: |
6867 return ConsString::cast(input)->ConsStringReadBlock(rbb, | 6868 return ConsString::cast(input)->ConsStringReadBlock(rbb, |
6868 offset_ptr, | 6869 offset_ptr, |
6869 max_chars); | 6870 max_chars); |
6870 case kExternalStringTag: | 6871 case kExternalStringTag: |
6871 if (input->IsAsciiRepresentation()) { | 6872 if (input->IsOneByteRepresentation()) { |
6872 return ExternalAsciiString::cast(input)->ExternalAsciiStringReadBlock( | 6873 return ExternalAsciiString::cast(input)->ExternalAsciiStringReadBlock( |
6873 &rbb->remaining, | 6874 &rbb->remaining, |
6874 offset_ptr, | 6875 offset_ptr, |
6875 max_chars); | 6876 max_chars); |
6876 } else { | 6877 } else { |
6877 ExternalTwoByteString::cast(input)-> | 6878 ExternalTwoByteString::cast(input)-> |
6878 ExternalTwoByteStringReadBlockIntoBuffer(rbb, | 6879 ExternalTwoByteStringReadBlockIntoBuffer(rbb, |
6879 offset_ptr, | 6880 offset_ptr, |
6880 max_chars); | 6881 max_chars); |
6881 return rbb->util_buffer; | 6882 return rbb->util_buffer; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6993 // to fill up a buffer. | 6994 // to fill up a buffer. |
6994 void String::ReadBlockIntoBuffer(String* input, | 6995 void String::ReadBlockIntoBuffer(String* input, |
6995 ReadBlockBuffer* rbb, | 6996 ReadBlockBuffer* rbb, |
6996 unsigned* offset_ptr, | 6997 unsigned* offset_ptr, |
6997 unsigned max_chars) { | 6998 unsigned max_chars) { |
6998 ASSERT(*offset_ptr <= (unsigned)input->length()); | 6999 ASSERT(*offset_ptr <= (unsigned)input->length()); |
6999 if (max_chars == 0) return; | 7000 if (max_chars == 0) return; |
7000 | 7001 |
7001 switch (StringShape(input).representation_tag()) { | 7002 switch (StringShape(input).representation_tag()) { |
7002 case kSeqStringTag: | 7003 case kSeqStringTag: |
7003 if (input->IsAsciiRepresentation()) { | 7004 if (input->IsOneByteRepresentation()) { |
7004 SeqOneByteString::cast(input)->SeqOneByteStringReadBlockIntoBuffer(rbb, | 7005 SeqOneByteString::cast(input)->SeqOneByteStringReadBlockIntoBuffer(rbb, |
7005 offset_ptr, | 7006 offset_ptr, |
7006 max_chars); | 7007 max_chars); |
7007 return; | 7008 return; |
7008 } else { | 7009 } else { |
7009 SeqTwoByteString::cast(input)->SeqTwoByteStringReadBlockIntoBuffer(rbb, | 7010 SeqTwoByteString::cast(input)->SeqTwoByteStringReadBlockIntoBuffer(rbb, |
7010 offset_ptr, | 7011 offset_ptr, |
7011 max_chars); | 7012 max_chars); |
7012 return; | 7013 return; |
7013 } | 7014 } |
7014 case kConsStringTag: | 7015 case kConsStringTag: |
7015 ConsString::cast(input)->ConsStringReadBlockIntoBuffer(rbb, | 7016 ConsString::cast(input)->ConsStringReadBlockIntoBuffer(rbb, |
7016 offset_ptr, | 7017 offset_ptr, |
7017 max_chars); | 7018 max_chars); |
7018 return; | 7019 return; |
7019 case kExternalStringTag: | 7020 case kExternalStringTag: |
7020 if (input->IsAsciiRepresentation()) { | 7021 if (input->IsOneByteRepresentation()) { |
7021 ExternalAsciiString::cast(input)-> | 7022 ExternalAsciiString::cast(input)-> |
7022 ExternalAsciiStringReadBlockIntoBuffer(rbb, offset_ptr, max_chars); | 7023 ExternalAsciiStringReadBlockIntoBuffer(rbb, offset_ptr, max_chars); |
7023 } else { | 7024 } else { |
7024 ExternalTwoByteString::cast(input)-> | 7025 ExternalTwoByteString::cast(input)-> |
7025 ExternalTwoByteStringReadBlockIntoBuffer(rbb, | 7026 ExternalTwoByteStringReadBlockIntoBuffer(rbb, |
7026 offset_ptr, | 7027 offset_ptr, |
7027 max_chars); | 7028 max_chars); |
7028 } | 7029 } |
7029 return; | 7030 return; |
7030 case kSlicedStringTag: | 7031 case kSlicedStringTag: |
(...skipping 6917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13948 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13949 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
13949 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13950 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
13950 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13951 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
13951 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13952 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
13952 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13953 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
13953 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13954 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
13954 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13955 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
13955 } | 13956 } |
13956 | 13957 |
13957 } } // namespace v8::internal | 13958 } } // namespace v8::internal |
OLD | NEW |