| 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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 : SequentialStringKey<uint8_t>(str, seed) { } | 492 : SequentialStringKey<uint8_t>(str, seed) { } |
| 493 | 493 |
| 494 virtual bool IsMatch(Object* string) { | 494 virtual bool IsMatch(Object* string) { |
| 495 return String::cast(string)->IsOneByteEqualTo(string_); | 495 return String::cast(string)->IsOneByteEqualTo(string_); |
| 496 } | 496 } |
| 497 | 497 |
| 498 virtual MaybeObject* AsObject(Heap* heap); | 498 virtual MaybeObject* AsObject(Heap* heap); |
| 499 }; | 499 }; |
| 500 | 500 |
| 501 | 501 |
| 502 class SubStringOneByteStringKey : public HashTableKey { | 502 template<class Char> |
| 503 class SubStringKey : public HashTableKey { |
| 503 public: | 504 public: |
| 504 explicit SubStringOneByteStringKey(Handle<SeqOneByteString> string, | 505 SubStringKey(Handle<String> string, int from, int length) |
| 505 int from, | 506 : string_(string), from_(from), length_(length) { |
| 506 int length) | 507 if (string_->IsSlicedString()) { |
| 507 : string_(string), from_(from), length_(length) { } | 508 string_ = Handle<String>(Unslice(*string_, &from_)); |
| 509 } |
| 510 ASSERT(string_->IsSeqString() || string->IsExternalString()); |
| 511 } |
| 508 | 512 |
| 509 virtual uint32_t Hash() { | 513 virtual uint32_t Hash() { |
| 510 ASSERT(length_ >= 0); | 514 ASSERT(length_ >= 0); |
| 511 ASSERT(from_ + length_ <= string_->length()); | 515 ASSERT(from_ + length_ <= string_->length()); |
| 512 uint8_t* chars = string_->GetChars() + from_; | 516 const Char* chars = GetChars() + from_; |
| 513 hash_field_ = StringHasher::HashSequentialString( | 517 hash_field_ = StringHasher::HashSequentialString( |
| 514 chars, length_, string_->GetHeap()->HashSeed()); | 518 chars, length_, string_->GetHeap()->HashSeed()); |
| 515 uint32_t result = hash_field_ >> String::kHashShift; | 519 uint32_t result = hash_field_ >> String::kHashShift; |
| 516 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 520 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| 517 return result; | 521 return result; |
| 518 } | 522 } |
| 519 | 523 |
| 520 | |
| 521 virtual uint32_t HashForObject(Object* other) { | 524 virtual uint32_t HashForObject(Object* other) { |
| 522 return String::cast(other)->Hash(); | 525 return String::cast(other)->Hash(); |
| 523 } | 526 } |
| 524 | 527 |
| 525 virtual bool IsMatch(Object* string) { | 528 virtual bool IsMatch(Object* string); |
| 526 Vector<const uint8_t> chars(string_->GetChars() + from_, length_); | |
| 527 return String::cast(string)->IsOneByteEqualTo(chars); | |
| 528 } | |
| 529 | |
| 530 virtual MaybeObject* AsObject(Heap* heap); | 529 virtual MaybeObject* AsObject(Heap* heap); |
| 531 | 530 |
| 532 private: | 531 private: |
| 533 Handle<SeqOneByteString> string_; | 532 const Char* GetChars(); |
| 533 String* Unslice(String* string, int* offset) { |
| 534 while (string->IsSlicedString()) { |
| 535 SlicedString* sliced = SlicedString::cast(string); |
| 536 *offset += sliced->offset(); |
| 537 string = sliced->parent(); |
| 538 } |
| 539 return string; |
| 540 } |
| 541 |
| 542 Handle<String> string_; |
| 534 int from_; | 543 int from_; |
| 535 int length_; | 544 int length_; |
| 536 uint32_t hash_field_; | 545 uint32_t hash_field_; |
| 537 }; | 546 }; |
| 538 | 547 |
| 539 | 548 |
| 540 class TwoByteStringKey : public SequentialStringKey<uc16> { | 549 class TwoByteStringKey : public SequentialStringKey<uc16> { |
| 541 public: | 550 public: |
| 542 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) | 551 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) |
| 543 : SequentialStringKey<uc16>(str, seed) { } | 552 : SequentialStringKey<uc16>(str, seed) { } |
| (...skipping 6250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6794 #undef READ_UINT32_FIELD | 6803 #undef READ_UINT32_FIELD |
| 6795 #undef WRITE_UINT32_FIELD | 6804 #undef WRITE_UINT32_FIELD |
| 6796 #undef READ_SHORT_FIELD | 6805 #undef READ_SHORT_FIELD |
| 6797 #undef WRITE_SHORT_FIELD | 6806 #undef WRITE_SHORT_FIELD |
| 6798 #undef READ_BYTE_FIELD | 6807 #undef READ_BYTE_FIELD |
| 6799 #undef WRITE_BYTE_FIELD | 6808 #undef WRITE_BYTE_FIELD |
| 6800 | 6809 |
| 6801 } } // namespace v8::internal | 6810 } } // namespace v8::internal |
| 6802 | 6811 |
| 6803 #endif // V8_OBJECTS_INL_H_ | 6812 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |