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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 uc32 FlatStringReader::Get(int index) { | 452 uc32 FlatStringReader::Get(int index) { |
453 ASSERT(0 <= index && index <= length_); | 453 ASSERT(0 <= index && index <= length_); |
454 if (is_ascii_) { | 454 if (is_ascii_) { |
455 return static_cast<const byte*>(start_)[index]; | 455 return static_cast<const byte*>(start_)[index]; |
456 } else { | 456 } else { |
457 return static_cast<const uc16*>(start_)[index]; | 457 return static_cast<const uc16*>(start_)[index]; |
458 } | 458 } |
459 } | 459 } |
460 | 460 |
461 | 461 |
| 462 template <typename Char> |
| 463 class SequentialStringKey : public HashTableKey { |
| 464 public: |
| 465 explicit SequentialStringKey(Vector<const Char> string, uint32_t seed) |
| 466 : string_(string), hash_field_(0), seed_(seed) { } |
| 467 |
| 468 virtual uint32_t Hash() { |
| 469 hash_field_ = StringHasher::HashSequentialString<Char>(string_.start(), |
| 470 string_.length(), |
| 471 seed_); |
| 472 |
| 473 uint32_t result = hash_field_ >> String::kHashShift; |
| 474 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| 475 return result; |
| 476 } |
| 477 |
| 478 |
| 479 virtual uint32_t HashForObject(Object* other) { |
| 480 return String::cast(other)->Hash(); |
| 481 } |
| 482 |
| 483 Vector<const Char> string_; |
| 484 uint32_t hash_field_; |
| 485 uint32_t seed_; |
| 486 }; |
| 487 |
| 488 |
| 489 class OneByteStringKey : public SequentialStringKey<uint8_t> { |
| 490 public: |
| 491 OneByteStringKey(Vector<const uint8_t> str, uint32_t seed) |
| 492 : SequentialStringKey<uint8_t>(str, seed) { } |
| 493 |
| 494 virtual bool IsMatch(Object* string) { |
| 495 return String::cast(string)->IsOneByteEqualTo(string_); |
| 496 } |
| 497 |
| 498 virtual MaybeObject* AsObject(Heap* heap); |
| 499 }; |
| 500 |
| 501 |
| 502 class SubStringOneByteStringKey : public HashTableKey { |
| 503 public: |
| 504 explicit SubStringOneByteStringKey(Handle<SeqOneByteString> string, |
| 505 int from, |
| 506 int length) |
| 507 : string_(string), from_(from), length_(length) { } |
| 508 |
| 509 virtual uint32_t Hash() { |
| 510 ASSERT(length_ >= 0); |
| 511 ASSERT(from_ + length_ <= string_->length()); |
| 512 uint8_t* chars = string_->GetChars() + from_; |
| 513 hash_field_ = StringHasher::HashSequentialString( |
| 514 chars, length_, string_->GetHeap()->HashSeed()); |
| 515 uint32_t result = hash_field_ >> String::kHashShift; |
| 516 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| 517 return result; |
| 518 } |
| 519 |
| 520 |
| 521 virtual uint32_t HashForObject(Object* other) { |
| 522 return String::cast(other)->Hash(); |
| 523 } |
| 524 |
| 525 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); |
| 531 |
| 532 private: |
| 533 Handle<SeqOneByteString> string_; |
| 534 int from_; |
| 535 int length_; |
| 536 uint32_t hash_field_; |
| 537 }; |
| 538 |
| 539 |
| 540 class TwoByteStringKey : public SequentialStringKey<uc16> { |
| 541 public: |
| 542 explicit TwoByteStringKey(Vector<const uc16> str, uint32_t seed) |
| 543 : SequentialStringKey<uc16>(str, seed) { } |
| 544 |
| 545 virtual bool IsMatch(Object* string) { |
| 546 return String::cast(string)->IsTwoByteEqualTo(string_); |
| 547 } |
| 548 |
| 549 virtual MaybeObject* AsObject(Heap* heap); |
| 550 }; |
| 551 |
| 552 |
| 553 // Utf8StringKey carries a vector of chars as key. |
| 554 class Utf8StringKey : public HashTableKey { |
| 555 public: |
| 556 explicit Utf8StringKey(Vector<const char> string, uint32_t seed) |
| 557 : string_(string), hash_field_(0), seed_(seed) { } |
| 558 |
| 559 virtual bool IsMatch(Object* string) { |
| 560 return String::cast(string)->IsUtf8EqualTo(string_); |
| 561 } |
| 562 |
| 563 virtual uint32_t Hash() { |
| 564 if (hash_field_ != 0) return hash_field_ >> String::kHashShift; |
| 565 hash_field_ = StringHasher::ComputeUtf8Hash(string_, seed_, &chars_); |
| 566 uint32_t result = hash_field_ >> String::kHashShift; |
| 567 ASSERT(result != 0); // Ensure that the hash value of 0 is never computed. |
| 568 return result; |
| 569 } |
| 570 |
| 571 virtual uint32_t HashForObject(Object* other) { |
| 572 return String::cast(other)->Hash(); |
| 573 } |
| 574 |
| 575 virtual MaybeObject* AsObject(Heap* heap) { |
| 576 if (hash_field_ == 0) Hash(); |
| 577 return heap->AllocateInternalizedStringFromUtf8(string_, |
| 578 chars_, |
| 579 hash_field_); |
| 580 } |
| 581 |
| 582 Vector<const char> string_; |
| 583 uint32_t hash_field_; |
| 584 int chars_; // Caches the number of characters when computing the hash code. |
| 585 uint32_t seed_; |
| 586 }; |
| 587 |
| 588 |
462 bool Object::IsNumber() { | 589 bool Object::IsNumber() { |
463 return IsSmi() || IsHeapNumber(); | 590 return IsSmi() || IsHeapNumber(); |
464 } | 591 } |
465 | 592 |
466 | 593 |
467 TYPE_CHECKER(ByteArray, BYTE_ARRAY_TYPE) | 594 TYPE_CHECKER(ByteArray, BYTE_ARRAY_TYPE) |
468 TYPE_CHECKER(FreeSpace, FREE_SPACE_TYPE) | 595 TYPE_CHECKER(FreeSpace, FREE_SPACE_TYPE) |
469 | 596 |
470 | 597 |
471 bool Object::IsFiller() { | 598 bool Object::IsFiller() { |
(...skipping 6192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6664 #undef WRITE_INT_FIELD | 6791 #undef WRITE_INT_FIELD |
6665 #undef READ_INTPTR_FIELD | 6792 #undef READ_INTPTR_FIELD |
6666 #undef WRITE_INTPTR_FIELD | 6793 #undef WRITE_INTPTR_FIELD |
6667 #undef READ_UINT32_FIELD | 6794 #undef READ_UINT32_FIELD |
6668 #undef WRITE_UINT32_FIELD | 6795 #undef WRITE_UINT32_FIELD |
6669 #undef READ_SHORT_FIELD | 6796 #undef READ_SHORT_FIELD |
6670 #undef WRITE_SHORT_FIELD | 6797 #undef WRITE_SHORT_FIELD |
6671 #undef READ_BYTE_FIELD | 6798 #undef READ_BYTE_FIELD |
6672 #undef WRITE_BYTE_FIELD | 6799 #undef WRITE_BYTE_FIELD |
6673 | 6800 |
6674 | |
6675 } } // namespace v8::internal | 6801 } } // namespace v8::internal |
6676 | 6802 |
6677 #endif // V8_OBJECTS_INL_H_ | 6803 #endif // V8_OBJECTS_INL_H_ |
OLD | NEW |