OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Review notes: | 5 // Review notes: |
6 // | 6 // |
7 // - The use of macros in these inline functions may seem superfluous | 7 // - The use of macros in these inline functions may seem superfluous |
8 // but it is absolutely needed to make sure gcc generates optimal | 8 // but it is absolutely needed to make sure gcc generates optimal |
9 // code. gcc is not happy when attempting to inline too deep. | 9 // code. gcc is not happy when attempting to inline too deep. |
10 // | 10 // |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 : SequentialStringKey<uint8_t>(str, seed) { } | 526 : SequentialStringKey<uint8_t>(str, seed) { } |
527 | 527 |
528 virtual bool IsMatch(Object* string) V8_OVERRIDE { | 528 virtual bool IsMatch(Object* string) V8_OVERRIDE { |
529 return String::cast(string)->IsOneByteEqualTo(string_); | 529 return String::cast(string)->IsOneByteEqualTo(string_); |
530 } | 530 } |
531 | 531 |
532 virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE; | 532 virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE; |
533 }; | 533 }; |
534 | 534 |
535 | 535 |
536 template<class Char> | 536 class SeqOneByteSubStringKey : public HashTableKey { |
537 class SubStringKey : public HashTableKey { | |
538 public: | 537 public: |
539 SubStringKey(Handle<String> string, int from, int length) | 538 SeqOneByteSubStringKey(Handle<SeqOneByteString> string, int from, int length) |
540 : string_(string), from_(from), length_(length) { | 539 : string_(string), from_(from), length_(length) { |
541 if (string_->IsSlicedString()) { | 540 DCHECK(string_->IsSeqOneByteString()); |
542 string_ = Handle<String>(Unslice(*string_, &from_)); | |
543 } | |
544 DCHECK(string_->IsSeqString() || string->IsExternalString()); | |
545 } | 541 } |
546 | 542 |
547 virtual uint32_t Hash() V8_OVERRIDE { | 543 virtual uint32_t Hash() V8_OVERRIDE { |
548 DCHECK(length_ >= 0); | 544 DCHECK(length_ >= 0); |
549 DCHECK(from_ + length_ <= string_->length()); | 545 DCHECK(from_ + length_ <= string_->length()); |
550 const Char* chars = GetChars() + from_; | 546 const uint8_t* chars = string_->GetChars() + from_; |
551 hash_field_ = StringHasher::HashSequentialString( | 547 hash_field_ = StringHasher::HashSequentialString( |
552 chars, length_, string_->GetHeap()->HashSeed()); | 548 chars, length_, string_->GetHeap()->HashSeed()); |
553 uint32_t result = hash_field_ >> String::kHashShift; | 549 uint32_t result = hash_field_ >> String::kHashShift; |
554 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. | 550 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. |
555 return result; | 551 return result; |
556 } | 552 } |
557 | 553 |
558 virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { | 554 virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { |
559 return String::cast(other)->Hash(); | 555 return String::cast(other)->Hash(); |
560 } | 556 } |
561 | 557 |
562 virtual bool IsMatch(Object* string) V8_OVERRIDE; | 558 virtual bool IsMatch(Object* string) V8_OVERRIDE; |
563 virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE; | 559 virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE; |
564 | 560 |
565 private: | 561 private: |
566 const Char* GetChars(); | 562 Handle<SeqOneByteString> string_; |
567 String* Unslice(String* string, int* offset) { | |
568 while (string->IsSlicedString()) { | |
569 SlicedString* sliced = SlicedString::cast(string); | |
570 *offset += sliced->offset(); | |
571 string = sliced->parent(); | |
572 } | |
573 return string; | |
574 } | |
575 | |
576 Handle<String> string_; | |
577 int from_; | 563 int from_; |
578 int length_; | 564 int length_; |
579 uint32_t hash_field_; | 565 uint32_t hash_field_; |
580 }; | 566 }; |
581 | 567 |
582 | 568 |
583 class TwoByteStringKey : public SequentialStringKey<uc16> { | 569 class TwoByteStringKey : public SequentialStringKey<uc16> { |
584 public: | 570 public: |
585 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) | 571 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) |
586 : SequentialStringKey<uc16>(str, seed) { } | 572 : SequentialStringKey<uc16>(str, seed) { } |
(...skipping 6696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7283 #undef READ_SHORT_FIELD | 7269 #undef READ_SHORT_FIELD |
7284 #undef WRITE_SHORT_FIELD | 7270 #undef WRITE_SHORT_FIELD |
7285 #undef READ_BYTE_FIELD | 7271 #undef READ_BYTE_FIELD |
7286 #undef WRITE_BYTE_FIELD | 7272 #undef WRITE_BYTE_FIELD |
7287 #undef NOBARRIER_READ_BYTE_FIELD | 7273 #undef NOBARRIER_READ_BYTE_FIELD |
7288 #undef NOBARRIER_WRITE_BYTE_FIELD | 7274 #undef NOBARRIER_WRITE_BYTE_FIELD |
7289 | 7275 |
7290 } } // namespace v8::internal | 7276 } } // namespace v8::internal |
7291 | 7277 |
7292 #endif // V8_OBJECTS_INL_H_ | 7278 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |