| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef V8_OBJECTS_H_ | 5 #ifndef V8_OBJECTS_H_ |
| 6 #define V8_OBJECTS_H_ | 6 #define V8_OBJECTS_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 | 9 |
| 10 #include "src/assert-scope.h" | 10 #include "src/assert-scope.h" |
| (...skipping 3861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3872 | 3872 |
| 3873 // Returns an OrderedHashTable (possibly |table|) with enough space | 3873 // Returns an OrderedHashTable (possibly |table|) with enough space |
| 3874 // to add at least one new element. | 3874 // to add at least one new element. |
| 3875 static Handle<Derived> EnsureGrowable(Handle<Derived> table); | 3875 static Handle<Derived> EnsureGrowable(Handle<Derived> table); |
| 3876 | 3876 |
| 3877 // Returns an OrderedHashTable (possibly |table|) that's shrunken | 3877 // Returns an OrderedHashTable (possibly |table|) that's shrunken |
| 3878 // if possible. | 3878 // if possible. |
| 3879 static Handle<Derived> Shrink(Handle<Derived> table); | 3879 static Handle<Derived> Shrink(Handle<Derived> table); |
| 3880 | 3880 |
| 3881 // Returns a new empty OrderedHashTable and records the clearing so that | 3881 // Returns a new empty OrderedHashTable and records the clearing so that |
| 3882 // exisiting iterators can be updated. | 3882 // existing iterators can be updated. |
| 3883 static Handle<Derived> Clear(Handle<Derived> table); | 3883 static Handle<Derived> Clear(Handle<Derived> table); |
| 3884 | 3884 |
| 3885 // Returns a true if the OrderedHashTable contains the key | 3885 // Returns a true if the OrderedHashTable contains the key |
| 3886 static bool HasKey(Handle<Derived> table, Handle<Object> key); | 3886 static bool HasKey(Handle<Derived> table, Handle<Object> key); |
| 3887 | 3887 |
| 3888 int NumberOfElements() { | 3888 int NumberOfElements() { |
| 3889 return Smi::cast(get(kNumberOfElementsIndex))->value(); | 3889 return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 3890 } | 3890 } |
| 3891 | 3891 |
| 3892 int NumberOfDeletedElements() { | 3892 int NumberOfDeletedElements() { |
| 3893 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); | 3893 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 3894 } | 3894 } |
| 3895 | 3895 |
| 3896 // Returns the number of contiguous entries in the data table, starting at 0, |
| 3897 // that either are real entries or have been deleted. |
| 3896 int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); } | 3898 int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); } |
| 3897 | 3899 |
| 3898 int NumberOfBuckets() { | 3900 int NumberOfBuckets() { |
| 3899 return Smi::cast(get(kNumberOfBucketsIndex))->value(); | 3901 return Smi::cast(get(kNumberOfBucketsIndex))->value(); |
| 3900 } | 3902 } |
| 3901 | 3903 |
| 3902 // Returns an index into |this| for the given entry. | 3904 // Returns an index into |this| for the given entry. |
| 3903 int EntryToIndex(int entry) { | 3905 int EntryToIndex(int entry) { |
| 3904 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize); | 3906 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize); |
| 3905 } | 3907 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3917 // If the object does not have an identity hash, it was never used as a key | 3919 // If the object does not have an identity hash, it was never used as a key |
| 3918 if (hash->IsUndefined()) return kNotFound; | 3920 if (hash->IsUndefined()) return kNotFound; |
| 3919 return HashToEntry(Smi::cast(hash)->value()); | 3921 return HashToEntry(Smi::cast(hash)->value()); |
| 3920 } | 3922 } |
| 3921 | 3923 |
| 3922 int NextChainEntry(int entry) { | 3924 int NextChainEntry(int entry) { |
| 3923 Object* next_entry = get(EntryToIndex(entry) + kChainOffset); | 3925 Object* next_entry = get(EntryToIndex(entry) + kChainOffset); |
| 3924 return Smi::cast(next_entry)->value(); | 3926 return Smi::cast(next_entry)->value(); |
| 3925 } | 3927 } |
| 3926 | 3928 |
| 3927 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } | 3929 // use KeyAt(i)->IsTheHole() to determine if this is a deleted entry. |
| 3930 Object* KeyAt(int entry) { |
| 3931 DCHECK_LT(entry, this->UsedCapacity()); |
| 3932 return get(EntryToIndex(entry)); |
| 3933 } |
| 3928 | 3934 |
| 3929 bool IsObsolete() { | 3935 bool IsObsolete() { |
| 3930 return !get(kNextTableIndex)->IsSmi(); | 3936 return !get(kNextTableIndex)->IsSmi(); |
| 3931 } | 3937 } |
| 3932 | 3938 |
| 3933 // The next newer table. This is only valid if the table is obsolete. | 3939 // The next newer table. This is only valid if the table is obsolete. |
| 3934 Derived* NextTable() { | 3940 Derived* NextTable() { |
| 3935 return Derived::cast(get(kNextTableIndex)); | 3941 return Derived::cast(get(kNextTableIndex)); |
| 3936 } | 3942 } |
| 3937 | 3943 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3978 } | 3984 } |
| 3979 | 3985 |
| 3980 void SetNumberOfElements(int num) { | 3986 void SetNumberOfElements(int num) { |
| 3981 set(kNumberOfElementsIndex, Smi::FromInt(num)); | 3987 set(kNumberOfElementsIndex, Smi::FromInt(num)); |
| 3982 } | 3988 } |
| 3983 | 3989 |
| 3984 void SetNumberOfDeletedElements(int num) { | 3990 void SetNumberOfDeletedElements(int num) { |
| 3985 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num)); | 3991 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num)); |
| 3986 } | 3992 } |
| 3987 | 3993 |
| 3994 // Returns the number elements that can fit into the allocated buffer. |
| 3988 int Capacity() { | 3995 int Capacity() { |
| 3989 return NumberOfBuckets() * kLoadFactor; | 3996 return NumberOfBuckets() * kLoadFactor; |
| 3990 } | 3997 } |
| 3991 | 3998 |
| 3992 void SetNextTable(Derived* next_table) { | 3999 void SetNextTable(Derived* next_table) { |
| 3993 set(kNextTableIndex, next_table); | 4000 set(kNextTableIndex, next_table); |
| 3994 } | 4001 } |
| 3995 | 4002 |
| 3996 void SetRemovedIndexAt(int index, int removed_index) { | 4003 void SetRemovedIndexAt(int index, int removed_index) { |
| 3997 return set(kRemovedHolesIndex + index, Smi::FromInt(removed_index)); | 4004 return set(kRemovedHolesIndex + index, Smi::FromInt(removed_index)); |
| (...skipping 6784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10782 } | 10789 } |
| 10783 return value; | 10790 return value; |
| 10784 } | 10791 } |
| 10785 }; | 10792 }; |
| 10786 | 10793 |
| 10787 | 10794 |
| 10788 } // NOLINT, false-positive due to second-order macros. | 10795 } // NOLINT, false-positive due to second-order macros. |
| 10789 } // NOLINT, false-positive due to second-order macros. | 10796 } // NOLINT, false-positive due to second-order macros. |
| 10790 | 10797 |
| 10791 #endif // V8_OBJECTS_H_ | 10798 #endif // V8_OBJECTS_H_ |
| OLD | NEW |