| 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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 uc32 FlatStringReader::Get(int index) { | 463 uc32 FlatStringReader::Get(int index) { |
| 464 ASSERT(0 <= index && index <= length_); | 464 ASSERT(0 <= index && index <= length_); |
| 465 if (is_ascii_) { | 465 if (is_ascii_) { |
| 466 return static_cast<const byte*>(start_)[index]; | 466 return static_cast<const byte*>(start_)[index]; |
| 467 } else { | 467 } else { |
| 468 return static_cast<const uc16*>(start_)[index]; | 468 return static_cast<const uc16*>(start_)[index]; |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 | 471 |
| 472 | 472 |
| 473 Handle<Object> HashTableKey::AsHandle(Isolate* isolate) { | |
| 474 CALL_HEAP_FUNCTION(isolate, AsObject(isolate->heap()), Object); | |
| 475 } | |
| 476 | |
| 477 | |
| 478 Handle<Object> StringTableShape::AsHandle(Isolate* isolate, HashTableKey* key) { | 473 Handle<Object> StringTableShape::AsHandle(Isolate* isolate, HashTableKey* key) { |
| 479 return key->AsHandle(isolate); | 474 return key->AsHandle(isolate); |
| 480 } | 475 } |
| 481 | 476 |
| 482 | 477 |
| 483 Handle<Object> MapCacheShape::AsHandle(Isolate* isolate, HashTableKey* key) { | 478 Handle<Object> MapCacheShape::AsHandle(Isolate* isolate, HashTableKey* key) { |
| 484 return key->AsHandle(isolate); | 479 return key->AsHandle(isolate); |
| 485 } | 480 } |
| 486 | 481 |
| 487 | 482 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 520 |
| 526 class OneByteStringKey : public SequentialStringKey<uint8_t> { | 521 class OneByteStringKey : public SequentialStringKey<uint8_t> { |
| 527 public: | 522 public: |
| 528 OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) | 523 OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) |
| 529 : SequentialStringKey<uint8_t>(str, seed) { } | 524 : SequentialStringKey<uint8_t>(str, seed) { } |
| 530 | 525 |
| 531 virtual bool IsMatch(Object* string) V8_OVERRIDE { | 526 virtual bool IsMatch(Object* string) V8_OVERRIDE { |
| 532 return String::cast(string)->IsOneByteEqualTo(string_); | 527 return String::cast(string)->IsOneByteEqualTo(string_); |
| 533 } | 528 } |
| 534 | 529 |
| 535 virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE; | 530 virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE; |
| 536 }; | 531 }; |
| 537 | 532 |
| 538 | 533 |
| 539 template<class Char> | 534 template<class Char> |
| 540 class SubStringKey : public HashTableKey { | 535 class SubStringKey : public HashTableKey { |
| 541 public: | 536 public: |
| 542 SubStringKey(Handle<String> string, int from, int length) | 537 SubStringKey(Handle<String> string, int from, int length) |
| 543 : string_(string), from_(from), length_(length) { | 538 : string_(string), from_(from), length_(length) { |
| 544 if (string_->IsSlicedString()) { | 539 if (string_->IsSlicedString()) { |
| 545 string_ = Handle<String>(Unslice(*string_, &from_)); | 540 string_ = Handle<String>(Unslice(*string_, &from_)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 556 uint32_t result = hash_field_ >> String::kHashShift; | 551 uint32_t result = hash_field_ >> String::kHashShift; |
| 557 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 552 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| 558 return result; | 553 return result; |
| 559 } | 554 } |
| 560 | 555 |
| 561 virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { | 556 virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { |
| 562 return String::cast(other)->Hash(); | 557 return String::cast(other)->Hash(); |
| 563 } | 558 } |
| 564 | 559 |
| 565 virtual bool IsMatch(Object* string) V8_OVERRIDE; | 560 virtual bool IsMatch(Object* string) V8_OVERRIDE; |
| 566 virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE; | 561 virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE; |
| 567 | 562 |
| 568 private: | 563 private: |
| 569 const Char* GetChars(); | 564 const Char* GetChars(); |
| 570 String* Unslice(String* string, int* offset) { | 565 String* Unslice(String* string, int* offset) { |
| 571 while (string->IsSlicedString()) { | 566 while (string->IsSlicedString()) { |
| 572 SlicedString* sliced = SlicedString::cast(string); | 567 SlicedString* sliced = SlicedString::cast(string); |
| 573 *offset += sliced->offset(); | 568 *offset += sliced->offset(); |
| 574 string = sliced->parent(); | 569 string = sliced->parent(); |
| 575 } | 570 } |
| 576 return string; | 571 return string; |
| 577 } | 572 } |
| 578 | 573 |
| 579 Handle<String> string_; | 574 Handle<String> string_; |
| 580 int from_; | 575 int from_; |
| 581 int length_; | 576 int length_; |
| 582 uint32_t hash_field_; | 577 uint32_t hash_field_; |
| 583 }; | 578 }; |
| 584 | 579 |
| 585 | 580 |
| 586 class TwoByteStringKey : public SequentialStringKey<uc16> { | 581 class TwoByteStringKey : public SequentialStringKey<uc16> { |
| 587 public: | 582 public: |
| 588 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) | 583 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) |
| 589 : SequentialStringKey<uc16>(str, seed) { } | 584 : SequentialStringKey<uc16>(str, seed) { } |
| 590 | 585 |
| 591 virtual bool IsMatch(Object* string) V8_OVERRIDE { | 586 virtual bool IsMatch(Object* string) V8_OVERRIDE { |
| 592 return String::cast(string)->IsTwoByteEqualTo(string_); | 587 return String::cast(string)->IsTwoByteEqualTo(string_); |
| 593 } | 588 } |
| 594 | 589 |
| 595 virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE; | 590 virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE; |
| 596 }; | 591 }; |
| 597 | 592 |
| 598 | 593 |
| 599 // Utf8StringKey carries a vector of chars as key. | 594 // Utf8StringKey carries a vector of chars as key. |
| 600 class Utf8StringKey : public HashTableKey { | 595 class Utf8StringKey : public HashTableKey { |
| 601 public: | 596 public: |
| 602 explicit Utf8StringKey(Vector<const char> string, uint32_t seed) | 597 explicit Utf8StringKey(Vector<const char> string, uint32_t seed) |
| 603 : string_(string), hash_field_(0), seed_(seed) { } | 598 : string_(string), hash_field_(0), seed_(seed) { } |
| 604 | 599 |
| 605 virtual bool IsMatch(Object* string) V8_OVERRIDE { | 600 virtual bool IsMatch(Object* string) V8_OVERRIDE { |
| 606 return String::cast(string)->IsUtf8EqualTo(string_); | 601 return String::cast(string)->IsUtf8EqualTo(string_); |
| 607 } | 602 } |
| 608 | 603 |
| 609 virtual uint32_t Hash() V8_OVERRIDE { | 604 virtual uint32_t Hash() V8_OVERRIDE { |
| 610 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; | 605 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; |
| 611 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); | 606 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); |
| 612 uint32_t result = hash_field_ >> String::kHashShift; | 607 uint32_t result = hash_field_ >> String::kHashShift; |
| 613 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. | 608 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| 614 return result; | 609 return result; |
| 615 } | 610 } |
| 616 | 611 |
| 617 virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { | 612 virtual uint32_t HashForObject(Object* other) V8_OVERRIDE { |
| 618 return String::cast(other)->Hash(); | 613 return String::cast(other)->Hash(); |
| 619 } | 614 } |
| 620 | 615 |
| 621 virtual MaybeObject* AsObject(Heap* heap) V8_OVERRIDE { | 616 virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE { |
| 622 if (hash_field_ == 0) Hash(); | 617 if (hash_field_ == 0) Hash(); |
| 623 return heap->AllocateInternalizedStringFromUtf8(string_, | 618 return isolate->factory()->NewInternalizedStringFromUtf8( |
| 624 chars_, | 619 string_, chars_, hash_field_); |
| 625 hash_field_); | |
| 626 } | 620 } |
| 627 | 621 |
| 628 Vector<const char> string_; | 622 Vector<const char> string_; |
| 629 uint32_t hash_field_; | 623 uint32_t hash_field_; |
| 630 int chars_; // Caches the number of characters when computing the hash code. | 624 int chars_; // Caches the number of characters when computing the hash code. |
| 631 uint32_t seed_; | 625 uint32_t seed_; |
| 632 }; | 626 }; |
| 633 | 627 |
| 634 | 628 |
| 635 bool Object::IsNumber() { | 629 bool Object::IsNumber() { |
| (...skipping 6407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7043 #undef READ_SHORT_FIELD | 7037 #undef READ_SHORT_FIELD |
| 7044 #undef WRITE_SHORT_FIELD | 7038 #undef WRITE_SHORT_FIELD |
| 7045 #undef READ_BYTE_FIELD | 7039 #undef READ_BYTE_FIELD |
| 7046 #undef WRITE_BYTE_FIELD | 7040 #undef WRITE_BYTE_FIELD |
| 7047 #undef NOBARRIER_READ_BYTE_FIELD | 7041 #undef NOBARRIER_READ_BYTE_FIELD |
| 7048 #undef NOBARRIER_WRITE_BYTE_FIELD | 7042 #undef NOBARRIER_WRITE_BYTE_FIELD |
| 7049 | 7043 |
| 7050 } } // namespace v8::internal | 7044 } } // namespace v8::internal |
| 7051 | 7045 |
| 7052 #endif // V8_OBJECTS_INL_H_ | 7046 #endif // V8_OBJECTS_INL_H_ |
| OLD | NEW |