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 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 Object* object; | 896 Object* object; |
897 String* result; | 897 String* result; |
898 if (IsOneByteRepresentation()) { | 898 if (IsOneByteRepresentation()) { |
899 { MaybeObject* maybe_object = | 899 { MaybeObject* maybe_object = |
900 heap->AllocateRawOneByteString(len, tenure); | 900 heap->AllocateRawOneByteString(len, tenure); |
901 if (!maybe_object->ToObject(&object)) return maybe_object; | 901 if (!maybe_object->ToObject(&object)) return maybe_object; |
902 } | 902 } |
903 result = String::cast(object); | 903 result = String::cast(object); |
904 String* first = cs->first(); | 904 String* first = cs->first(); |
905 int first_length = first->length(); | 905 int first_length = first->length(); |
906 char* dest = SeqOneByteString::cast(result)->GetChars(); | 906 uint8_t* dest = SeqOneByteString::cast(result)->GetChars(); |
907 WriteToFlat(first, dest, 0, first_length); | 907 WriteToFlat(first, dest, 0, first_length); |
908 String* second = cs->second(); | 908 String* second = cs->second(); |
909 WriteToFlat(second, | 909 WriteToFlat(second, |
910 dest + first_length, | 910 dest + first_length, |
911 0, | 911 0, |
912 len - first_length); | 912 len - first_length); |
913 } else { | 913 } else { |
914 { MaybeObject* maybe_object = | 914 { MaybeObject* maybe_object = |
915 heap->AllocateRawTwoByteString(len, tenure); | 915 heap->AllocateRawTwoByteString(len, tenure); |
916 if (!maybe_object->ToObject(&object)) return maybe_object; | 916 if (!maybe_object->ToObject(&object)) return maybe_object; |
(...skipping 5637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6554 } | 6554 } |
6555 if (shape.representation_tag() == kSlicedStringTag) { | 6555 if (shape.representation_tag() == kSlicedStringTag) { |
6556 SlicedString* slice = SlicedString::cast(string); | 6556 SlicedString* slice = SlicedString::cast(string); |
6557 offset = slice->offset(); | 6557 offset = slice->offset(); |
6558 string = slice->parent(); | 6558 string = slice->parent(); |
6559 shape = StringShape(string); | 6559 shape = StringShape(string); |
6560 ASSERT(shape.representation_tag() != kConsStringTag && | 6560 ASSERT(shape.representation_tag() != kConsStringTag && |
6561 shape.representation_tag() != kSlicedStringTag); | 6561 shape.representation_tag() != kSlicedStringTag); |
6562 } | 6562 } |
6563 if (shape.encoding_tag() == kOneByteStringTag) { | 6563 if (shape.encoding_tag() == kOneByteStringTag) { |
6564 const char* start; | 6564 const uint8_t* start; |
6565 if (shape.representation_tag() == kSeqStringTag) { | 6565 if (shape.representation_tag() == kSeqStringTag) { |
6566 start = SeqOneByteString::cast(string)->GetChars(); | 6566 start = SeqOneByteString::cast(string)->GetChars(); |
6567 } else { | 6567 } else { |
6568 start = ExternalAsciiString::cast(string)->GetChars(); | 6568 start = ExternalAsciiString::cast(string)->GetChars(); |
6569 } | 6569 } |
6570 return FlatContent(Vector<const char>(start + offset, length)); | 6570 return FlatContent(Vector<const uint8_t>(start + offset, length)); |
6571 } else { | 6571 } else { |
6572 ASSERT(shape.encoding_tag() == kTwoByteStringTag); | 6572 ASSERT(shape.encoding_tag() == kTwoByteStringTag); |
6573 const uc16* start; | 6573 const uc16* start; |
6574 if (shape.representation_tag() == kSeqStringTag) { | 6574 if (shape.representation_tag() == kSeqStringTag) { |
6575 start = SeqTwoByteString::cast(string)->GetChars(); | 6575 start = SeqTwoByteString::cast(string)->GetChars(); |
6576 } else { | 6576 } else { |
6577 start = ExternalTwoByteString::cast(string)->GetChars(); | 6577 start = ExternalTwoByteString::cast(string)->GetChars(); |
6578 } | 6578 } |
6579 return FlatContent(Vector<const uc16>(start + offset, length)); | 6579 return FlatContent(Vector<const uc16>(start + offset, length)); |
6580 } | 6580 } |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6763 | 6763 |
6764 | 6764 |
6765 void FlatStringReader::PostGarbageCollection() { | 6765 void FlatStringReader::PostGarbageCollection() { |
6766 if (str_ == NULL) return; | 6766 if (str_ == NULL) return; |
6767 Handle<String> str(str_); | 6767 Handle<String> str(str_); |
6768 ASSERT(str->IsFlat()); | 6768 ASSERT(str->IsFlat()); |
6769 String::FlatContent content = str->GetFlatContent(); | 6769 String::FlatContent content = str->GetFlatContent(); |
6770 ASSERT(content.IsFlat()); | 6770 ASSERT(content.IsFlat()); |
6771 is_ascii_ = content.IsAscii(); | 6771 is_ascii_ = content.IsAscii(); |
6772 if (is_ascii_) { | 6772 if (is_ascii_) { |
6773 start_ = content.ToAsciiVector().start(); | 6773 start_ = content.ToOneByteVector().start(); |
6774 } else { | 6774 } else { |
6775 start_ = content.ToUC16Vector().start(); | 6775 start_ = content.ToUC16Vector().start(); |
6776 } | 6776 } |
6777 } | 6777 } |
6778 | 6778 |
6779 | 6779 |
6780 String* ConsStringIteratorOp::Operate(String* string, | 6780 String* ConsStringIteratorOp::Operate(String* string, |
6781 unsigned* offset_out, | 6781 unsigned* offset_out, |
6782 int32_t* type_out, | 6782 int32_t* type_out, |
6783 unsigned* length_out) { | 6783 unsigned* length_out) { |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7247 // We know the strings are both non-empty. Compare the first chars | 7247 // We know the strings are both non-empty. Compare the first chars |
7248 // before we try to flatten the strings. | 7248 // before we try to flatten the strings. |
7249 if (this->Get(0) != other->Get(0)) return false; | 7249 if (this->Get(0) != other->Get(0)) return false; |
7250 | 7250 |
7251 String* lhs = this->TryFlattenGetString(); | 7251 String* lhs = this->TryFlattenGetString(); |
7252 String* rhs = other->TryFlattenGetString(); | 7252 String* rhs = other->TryFlattenGetString(); |
7253 | 7253 |
7254 // TODO(dcarney): Compare all types of flat strings with a Visitor. | 7254 // TODO(dcarney): Compare all types of flat strings with a Visitor. |
7255 if (StringShape(lhs).IsSequentialAscii() && | 7255 if (StringShape(lhs).IsSequentialAscii() && |
7256 StringShape(rhs).IsSequentialAscii()) { | 7256 StringShape(rhs).IsSequentialAscii()) { |
7257 const char* str1 = SeqOneByteString::cast(lhs)->GetChars(); | 7257 const uint8_t* str1 = SeqOneByteString::cast(lhs)->GetChars(); |
7258 const char* str2 = SeqOneByteString::cast(rhs)->GetChars(); | 7258 const uint8_t* str2 = SeqOneByteString::cast(rhs)->GetChars(); |
7259 return CompareRawStringContents(str1, str2, len); | 7259 return CompareRawStringContents(str1, str2, len); |
7260 } | 7260 } |
7261 | 7261 |
7262 Isolate* isolate = GetIsolate(); | 7262 Isolate* isolate = GetIsolate(); |
7263 StringComparator comparator(isolate->objects_string_compare_iterator_a(), | 7263 StringComparator comparator(isolate->objects_string_compare_iterator_a(), |
7264 isolate->objects_string_compare_iterator_b()); | 7264 isolate->objects_string_compare_iterator_b()); |
7265 | 7265 |
7266 return comparator.Equals(static_cast<unsigned>(len), lhs, rhs); | 7266 return comparator.Equals(static_cast<unsigned>(len), lhs, rhs); |
7267 } | 7267 } |
7268 | 7268 |
(...skipping 4249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11518 class SubStringOneByteSymbolKey : public HashTableKey { | 11518 class SubStringOneByteSymbolKey : public HashTableKey { |
11519 public: | 11519 public: |
11520 explicit SubStringOneByteSymbolKey(Handle<SeqOneByteString> string, | 11520 explicit SubStringOneByteSymbolKey(Handle<SeqOneByteString> string, |
11521 int from, | 11521 int from, |
11522 int length) | 11522 int length) |
11523 : string_(string), from_(from), length_(length) { } | 11523 : string_(string), from_(from), length_(length) { } |
11524 | 11524 |
11525 uint32_t Hash() { | 11525 uint32_t Hash() { |
11526 ASSERT(length_ >= 0); | 11526 ASSERT(length_ >= 0); |
11527 ASSERT(from_ + length_ <= string_->length()); | 11527 ASSERT(from_ + length_ <= string_->length()); |
11528 char* chars = string_->GetChars() + from_; | 11528 uint8_t* chars = string_->GetChars() + from_; |
11529 hash_field_ = StringHasher::HashSequentialString( | 11529 hash_field_ = StringHasher::HashSequentialString( |
11530 chars, length_, string_->GetHeap()->HashSeed()); | 11530 chars, length_, string_->GetHeap()->HashSeed()); |
11531 uint32_t result = hash_field_ >> String::kHashShift; | 11531 uint32_t result = hash_field_ >> String::kHashShift; |
11532 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 11532 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
11533 return result; | 11533 return result; |
11534 } | 11534 } |
11535 | 11535 |
11536 | 11536 |
11537 uint32_t HashForObject(Object* other) { | 11537 uint32_t HashForObject(Object* other) { |
11538 return String::cast(other)->Hash(); | 11538 return String::cast(other)->Hash(); |
11539 } | 11539 } |
11540 | 11540 |
11541 bool IsMatch(Object* string) { | 11541 bool IsMatch(Object* string) { |
11542 Vector<const uint8_t> chars(string_->GetCharsU() + from_, length_); | 11542 Vector<const uint8_t> chars(string_->GetChars() + from_, length_); |
11543 return String::cast(string)->IsOneByteEqualTo(chars); | 11543 return String::cast(string)->IsOneByteEqualTo(chars); |
11544 } | 11544 } |
11545 | 11545 |
11546 MaybeObject* AsObject() { | 11546 MaybeObject* AsObject() { |
11547 if (hash_field_ == 0) Hash(); | 11547 if (hash_field_ == 0) Hash(); |
11548 Vector<const uint8_t> chars( | 11548 Vector<const uint8_t> chars(string_->GetChars() + from_, length_); |
11549 reinterpret_cast<uint8_t*>(string_->GetChars()) + from_, | |
11550 length_); | |
11551 return HEAP->AllocateOneByteSymbol(chars, hash_field_); | 11549 return HEAP->AllocateOneByteSymbol(chars, hash_field_); |
11552 } | 11550 } |
11553 | 11551 |
11554 private: | 11552 private: |
11555 Handle<SeqOneByteString> string_; | 11553 Handle<SeqOneByteString> string_; |
11556 int from_; | 11554 int from_; |
11557 int length_; | 11555 int length_; |
11558 uint32_t hash_field_; | 11556 uint32_t hash_field_; |
11559 }; | 11557 }; |
11560 | 11558 |
(...skipping 2221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13782 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); | 13780 set_year(Smi::FromInt(year), SKIP_WRITE_BARRIER); |
13783 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); | 13781 set_month(Smi::FromInt(month), SKIP_WRITE_BARRIER); |
13784 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); | 13782 set_day(Smi::FromInt(day), SKIP_WRITE_BARRIER); |
13785 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); | 13783 set_weekday(Smi::FromInt(weekday), SKIP_WRITE_BARRIER); |
13786 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); | 13784 set_hour(Smi::FromInt(hour), SKIP_WRITE_BARRIER); |
13787 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); | 13785 set_min(Smi::FromInt(min), SKIP_WRITE_BARRIER); |
13788 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); | 13786 set_sec(Smi::FromInt(sec), SKIP_WRITE_BARRIER); |
13789 } | 13787 } |
13790 | 13788 |
13791 } } // namespace v8::internal | 13789 } } // namespace v8::internal |
OLD | NEW |