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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 HashTableKey* key) { | 502 HashTableKey* key) { |
503 return key->AsHandle(isolate); | 503 return key->AsHandle(isolate); |
504 } | 504 } |
505 | 505 |
506 template <typename Char> | 506 template <typename Char> |
507 class SequentialStringKey : public HashTableKey { | 507 class SequentialStringKey : public HashTableKey { |
508 public: | 508 public: |
509 explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) | 509 explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) |
510 : string_(string), hash_field_(0), seed_(seed) { } | 510 : string_(string), hash_field_(0), seed_(seed) { } |
511 | 511 |
512 uint32_t Hash() OVERRIDE { | 512 uint32_t Hash() override { |
513 hash_field_ = StringHasher::HashSequentialString<Char>(string_.start(), | 513 hash_field_ = StringHasher::HashSequentialString<Char>(string_.start(), |
514 string_.length(), | 514 string_.length(), |
515 seed_); | 515 seed_); |
516 | 516 |
517 uint32_t result = hash_field_ >> String::kHashShift; | 517 uint32_t result = hash_field_ >> String::kHashShift; |
518 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. | 518 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. |
519 return result; | 519 return result; |
520 } | 520 } |
521 | 521 |
522 | 522 |
523 uint32_t HashForObject(Object* other) OVERRIDE { | 523 uint32_t HashForObject(Object* other) override { |
524 return String::cast(other)->Hash(); | 524 return String::cast(other)->Hash(); |
525 } | 525 } |
526 | 526 |
527 Vector<const Char> string_; | 527 Vector<const Char> string_; |
528 uint32_t hash_field_; | 528 uint32_t hash_field_; |
529 uint32_t seed_; | 529 uint32_t seed_; |
530 }; | 530 }; |
531 | 531 |
532 | 532 |
533 class OneByteStringKey : public SequentialStringKey<uint8_t> { | 533 class OneByteStringKey : public SequentialStringKey<uint8_t> { |
534 public: | 534 public: |
535 OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) | 535 OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) |
536 : SequentialStringKey<uint8_t>(str, seed) { } | 536 : SequentialStringKey<uint8_t>(str, seed) { } |
537 | 537 |
538 bool IsMatch(Object* string) OVERRIDE { | 538 bool IsMatch(Object* string) override { |
539 return String::cast(string)->IsOneByteEqualTo(string_); | 539 return String::cast(string)->IsOneByteEqualTo(string_); |
540 } | 540 } |
541 | 541 |
542 Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; | 542 Handle<Object> AsHandle(Isolate* isolate) override; |
543 }; | 543 }; |
544 | 544 |
545 | 545 |
546 class SeqOneByteSubStringKey : public HashTableKey { | 546 class SeqOneByteSubStringKey : public HashTableKey { |
547 public: | 547 public: |
548 SeqOneByteSubStringKey(Handle<SeqOneByteString> string, int from, int length) | 548 SeqOneByteSubStringKey(Handle<SeqOneByteString> string, int from, int length) |
549 : string_(string), from_(from), length_(length) { | 549 : string_(string), from_(from), length_(length) { |
550 DCHECK(string_->IsSeqOneByteString()); | 550 DCHECK(string_->IsSeqOneByteString()); |
551 } | 551 } |
552 | 552 |
553 uint32_t Hash() OVERRIDE { | 553 uint32_t Hash() override { |
554 DCHECK(length_ >= 0); | 554 DCHECK(length_ >= 0); |
555 DCHECK(from_ + length_ <= string_->length()); | 555 DCHECK(from_ + length_ <= string_->length()); |
556 const uint8_t* chars = string_->GetChars() + from_; | 556 const uint8_t* chars = string_->GetChars() + from_; |
557 hash_field_ = StringHasher::HashSequentialString( | 557 hash_field_ = StringHasher::HashSequentialString( |
558 chars, length_, string_->GetHeap()->HashSeed()); | 558 chars, length_, string_->GetHeap()->HashSeed()); |
559 uint32_t result = hash_field_ >> String::kHashShift; | 559 uint32_t result = hash_field_ >> String::kHashShift; |
560 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. | 560 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. |
561 return result; | 561 return result; |
562 } | 562 } |
563 | 563 |
564 uint32_t HashForObject(Object* other) OVERRIDE { | 564 uint32_t HashForObject(Object* other) override { |
565 return String::cast(other)->Hash(); | 565 return String::cast(other)->Hash(); |
566 } | 566 } |
567 | 567 |
568 bool IsMatch(Object* string) OVERRIDE; | 568 bool IsMatch(Object* string) override; |
569 Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; | 569 Handle<Object> AsHandle(Isolate* isolate) override; |
570 | 570 |
571 private: | 571 private: |
572 Handle<SeqOneByteString> string_; | 572 Handle<SeqOneByteString> string_; |
573 int from_; | 573 int from_; |
574 int length_; | 574 int length_; |
575 uint32_t hash_field_; | 575 uint32_t hash_field_; |
576 }; | 576 }; |
577 | 577 |
578 | 578 |
579 class TwoByteStringKey : public SequentialStringKey<uc16> { | 579 class TwoByteStringKey : public SequentialStringKey<uc16> { |
580 public: | 580 public: |
581 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) | 581 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) |
582 : SequentialStringKey<uc16>(str, seed) { } | 582 : SequentialStringKey<uc16>(str, seed) { } |
583 | 583 |
584 bool IsMatch(Object* string) OVERRIDE { | 584 bool IsMatch(Object* string) override { |
585 return String::cast(string)->IsTwoByteEqualTo(string_); | 585 return String::cast(string)->IsTwoByteEqualTo(string_); |
586 } | 586 } |
587 | 587 |
588 Handle<Object> AsHandle(Isolate* isolate) OVERRIDE; | 588 Handle<Object> AsHandle(Isolate* isolate) override; |
589 }; | 589 }; |
590 | 590 |
591 | 591 |
592 // Utf8StringKey carries a vector of chars as key. | 592 // Utf8StringKey carries a vector of chars as key. |
593 class Utf8StringKey : public HashTableKey { | 593 class Utf8StringKey : public HashTableKey { |
594 public: | 594 public: |
595 explicit Utf8StringKey(Vector<const char> string, uint32_t seed) | 595 explicit Utf8StringKey(Vector<const char> string, uint32_t seed) |
596 : string_(string), hash_field_(0), seed_(seed) { } | 596 : string_(string), hash_field_(0), seed_(seed) { } |
597 | 597 |
598 bool IsMatch(Object* string) OVERRIDE { | 598 bool IsMatch(Object* string) override { |
599 return String::cast(string)->IsUtf8EqualTo(string_); | 599 return String::cast(string)->IsUtf8EqualTo(string_); |
600 } | 600 } |
601 | 601 |
602 uint32_t Hash() OVERRIDE { | 602 uint32_t Hash() override { |
603 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; | 603 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; |
604 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); | 604 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); |
605 uint32_t result = hash_field_ >> String::kHashShift; | 605 uint32_t result = hash_field_ >> String::kHashShift; |
606 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. | 606 DCHECK(result != 0); // Ensure that the hash value of 0 is never computed. |
607 return result; | 607 return result; |
608 } | 608 } |
609 | 609 |
610 uint32_t HashForObject(Object* other) OVERRIDE { | 610 uint32_t HashForObject(Object* other) override { |
611 return String::cast(other)->Hash(); | 611 return String::cast(other)->Hash(); |
612 } | 612 } |
613 | 613 |
614 Handle<Object> AsHandle(Isolate* isolate) OVERRIDE { | 614 Handle<Object> AsHandle(Isolate* isolate) override { |
615 if (hash_field_ == 0) Hash(); | 615 if (hash_field_ == 0) Hash(); |
616 return isolate->factory()->NewInternalizedStringFromUtf8( | 616 return isolate->factory()->NewInternalizedStringFromUtf8( |
617 string_, chars_, hash_field_); | 617 string_, chars_, hash_field_); |
618 } | 618 } |
619 | 619 |
620 Vector<const char> string_; | 620 Vector<const char> string_; |
621 uint32_t hash_field_; | 621 uint32_t hash_field_; |
622 int chars_; // Caches the number of characters when computing the hash code. | 622 int chars_; // Caches the number of characters when computing the hash code. |
623 uint32_t seed_; | 623 uint32_t seed_; |
624 }; | 624 }; |
(...skipping 6836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7461 | 7461 |
7462 Object* JSMapIterator::CurrentValue() { | 7462 Object* JSMapIterator::CurrentValue() { |
7463 OrderedHashMap* table(OrderedHashMap::cast(this->table())); | 7463 OrderedHashMap* table(OrderedHashMap::cast(this->table())); |
7464 int index = Smi::cast(this->index())->value(); | 7464 int index = Smi::cast(this->index())->value(); |
7465 Object* value = table->ValueAt(index); | 7465 Object* value = table->ValueAt(index); |
7466 DCHECK(!value->IsTheHole()); | 7466 DCHECK(!value->IsTheHole()); |
7467 return value; | 7467 return value; |
7468 } | 7468 } |
7469 | 7469 |
7470 | 7470 |
7471 class String::SubStringRange::iterator FINAL { | 7471 class String::SubStringRange::iterator final { |
7472 public: | 7472 public: |
7473 typedef std::forward_iterator_tag iterator_category; | 7473 typedef std::forward_iterator_tag iterator_category; |
7474 typedef int difference_type; | 7474 typedef int difference_type; |
7475 typedef uc16 value_type; | 7475 typedef uc16 value_type; |
7476 typedef uc16* pointer; | 7476 typedef uc16* pointer; |
7477 typedef uc16& reference; | 7477 typedef uc16& reference; |
7478 | 7478 |
7479 iterator(const iterator& other) | 7479 iterator(const iterator& other) |
7480 : content_(other.content_), offset_(other.offset_) {} | 7480 : content_(other.content_), offset_(other.offset_) {} |
7481 | 7481 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7540 #undef READ_SHORT_FIELD | 7540 #undef READ_SHORT_FIELD |
7541 #undef WRITE_SHORT_FIELD | 7541 #undef WRITE_SHORT_FIELD |
7542 #undef READ_BYTE_FIELD | 7542 #undef READ_BYTE_FIELD |
7543 #undef WRITE_BYTE_FIELD | 7543 #undef WRITE_BYTE_FIELD |
7544 #undef NOBARRIER_READ_BYTE_FIELD | 7544 #undef NOBARRIER_READ_BYTE_FIELD |
7545 #undef NOBARRIER_WRITE_BYTE_FIELD | 7545 #undef NOBARRIER_WRITE_BYTE_FIELD |
7546 | 7546 |
7547 } } // namespace v8::internal | 7547 } } // namespace v8::internal |
7548 | 7548 |
7549 #endif // V8_OBJECTS_INL_H_ | 7549 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |