Commit 62af397b authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[cleanup] Use RootIndex instead of int to avoid casting

Bug: v8:8015
Change-Id: I1a423b356d09bdf46d49d69fb83cc24acabb6313
Reviewed-on: https://chromium-review.googlesource.com/1238550Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56174}
parent 7431175b
......@@ -2062,8 +2062,7 @@ TNode<Object> WeakCollectionsBuiltinsAssembler::AllocateTable(
TNode<FixedArray> table = CAST(
AllocateFixedArray(HOLEY_ELEMENTS, length, kAllowLargeObjectAllocation));
RootIndex map_root_index =
static_cast<RootIndex>(EphemeronHashTableShape::GetMapRootIndex());
RootIndex map_root_index = EphemeronHashTableShape::GetMapRootIndex();
StoreMapNoWriteBarrier(table, map_root_index);
StoreFixedArrayElement(table, EphemeronHashTable::kNumberOfElementsIndex,
SmiConstant(0), SKIP_WRITE_BARRIER);
......
......@@ -3437,7 +3437,7 @@ Node* CodeStubAssembler::AllocateOrderedHashTable() {
const ElementsKind elements_kind = HOLEY_ELEMENTS;
TNode<IntPtrT> length_intptr = IntPtrConstant(kFixedArrayLength);
TNode<Map> fixed_array_map =
CAST(LoadRoot(static_cast<RootIndex>(CollectionType::GetMapRootIndex())));
CAST(LoadRoot(CollectionType::GetMapRootIndex()));
TNode<FixedArray> table =
CAST(AllocateFixedArray(elements_kind, length_intptr,
kAllowLargeObjectAllocation, fixed_array_map));
......@@ -3511,7 +3511,7 @@ TNode<CollectionType> CodeStubAssembler::AllocateSmallOrderedHashTable(
// Allocate the table and add the proper map.
TNode<Map> small_ordered_hash_map =
CAST(LoadRoot(static_cast<RootIndex>(CollectionType::GetMapRootIndex())));
CAST(LoadRoot(CollectionType::GetMapRootIndex()));
TNode<Object> table_obj = CAST(AllocateInNewSpace(total_size_word_aligned));
StoreMapNoWriteBarrier(table_obj, small_ordered_hash_map);
TNode<CollectionType> table = UncheckedCast<CollectionType>(table_obj);
......
......@@ -1447,8 +1447,8 @@ uint32_t StringTableShape::HashForObject(Isolate* isolate, Object* object) {
return String::cast(object)->Hash();
}
int StringTableShape::GetMapRootIndex() {
return static_cast<int>(RootIndex::kStringTableMap);
RootIndex StringTableShape::GetMapRootIndex() {
return RootIndex::kStringTableMap;
}
bool NumberDictionary::requires_slow_elements() {
......@@ -1846,14 +1846,14 @@ Object* GlobalDictionaryShape::Unwrap(Object* object) {
return PropertyCell::cast(object)->name();
}
int GlobalDictionaryShape::GetMapRootIndex() {
return static_cast<int>(RootIndex::kGlobalDictionaryMap);
RootIndex GlobalDictionaryShape::GetMapRootIndex() {
return RootIndex::kGlobalDictionaryMap;
}
Name* NameDictionary::NameAt(int entry) { return Name::cast(KeyAt(entry)); }
int NameDictionaryShape::GetMapRootIndex() {
return static_cast<int>(RootIndex::kNameDictionaryMap);
RootIndex NameDictionaryShape::GetMapRootIndex() {
return RootIndex::kNameDictionaryMap;
}
PropertyCell* GlobalDictionary::CellAt(int entry) {
......@@ -1905,12 +1905,12 @@ Handle<Object> NumberDictionaryBaseShape::AsHandle(Isolate* isolate,
return isolate->factory()->NewNumberFromUint(key);
}
int NumberDictionaryShape::GetMapRootIndex() {
return static_cast<int>(RootIndex::kNumberDictionaryMap);
RootIndex NumberDictionaryShape::GetMapRootIndex() {
return RootIndex::kNumberDictionaryMap;
}
int SimpleNumberDictionaryShape::GetMapRootIndex() {
return static_cast<int>(RootIndex::kSimpleNumberDictionaryMap);
RootIndex SimpleNumberDictionaryShape::GetMapRootIndex() {
return RootIndex::kSimpleNumberDictionaryMap;
}
bool NameDictionaryShape::IsMatch(Handle<Name> key, Object* other) {
......
......@@ -16640,7 +16640,7 @@ Handle<Derived> HashTable<Derived, Shape>::NewInternal(
Isolate* isolate, int capacity, PretenureFlag pretenure) {
Factory* factory = isolate->factory();
int length = EntryToIndex(capacity);
RootIndex map_root_index = static_cast<RootIndex>(Shape::GetMapRootIndex());
RootIndex map_root_index = Shape::GetMapRootIndex();
Handle<FixedArray> array =
factory->NewFixedArrayWithMap(map_root_index, length, pretenure);
Handle<Derived> table = Handle<Derived>::cast(array);
......
......@@ -113,7 +113,7 @@ class NameDictionaryShape : public BaseDictionaryShape<Handle<Name>> {
static inline uint32_t Hash(Isolate* isolate, Handle<Name> key);
static inline uint32_t HashForObject(Isolate* isolate, Object* object);
static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key);
static inline int GetMapRootIndex();
static inline RootIndex GetMapRootIndex();
static const int kPrefixSize = 2;
static const int kEntrySize = 3;
static const int kEntryValueIndex = 1;
......@@ -216,7 +216,7 @@ class GlobalDictionaryShape : public NameDictionaryShape {
static inline Object* Unwrap(Object* key);
static inline bool IsKey(ReadOnlyRoots roots, Object* k);
static inline bool IsLive(ReadOnlyRoots roots, Object* key);
static inline int GetMapRootIndex();
static inline RootIndex GetMapRootIndex();
};
class GlobalDictionary
......@@ -246,7 +246,7 @@ class NumberDictionaryShape : public NumberDictionaryBaseShape {
static const int kPrefixSize = 1;
static const int kEntrySize = 3;
static inline int GetMapRootIndex();
static inline RootIndex GetMapRootIndex();
};
class SimpleNumberDictionaryShape : public NumberDictionaryBaseShape {
......@@ -266,7 +266,7 @@ class SimpleNumberDictionaryShape : public NumberDictionaryBaseShape {
UNREACHABLE();
}
static inline int GetMapRootIndex();
static inline RootIndex GetMapRootIndex();
};
extern template class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE)
......
......@@ -58,12 +58,12 @@ void HashTableBase::SetNumberOfDeletedElements(int nod) {
}
template <typename Key>
int BaseShape<Key>::GetMapRootIndex() {
return static_cast<int>(RootIndex::kHashTableMap);
RootIndex BaseShape<Key>::GetMapRootIndex() {
return RootIndex::kHashTableMap;
}
int EphemeronHashTableShape::GetMapRootIndex() {
return static_cast<int>(RootIndex::kEphemeronHashTableMap);
RootIndex EphemeronHashTableShape::GetMapRootIndex() {
return RootIndex::kEphemeronHashTableMap;
}
template <typename Derived, typename Shape>
......
......@@ -55,7 +55,7 @@ template <typename KeyT>
class BaseShape {
public:
typedef KeyT Key;
static inline int GetMapRootIndex();
static inline RootIndex GetMapRootIndex();
static const bool kNeedsHoleCheck = true;
static Object* Unwrap(Object* key) { return key; }
static inline bool IsKey(ReadOnlyRoots roots, Object* key);
......@@ -321,7 +321,7 @@ class ObjectHashTable
class EphemeronHashTableShape : public ObjectHashTableShape {
public:
static inline int GetMapRootIndex();
static inline RootIndex GetMapRootIndex();
};
// EphemeronHashTable is similar to ObjectHashTable but gets special treatment
......
......@@ -13,20 +13,20 @@
namespace v8 {
namespace internal {
int OrderedHashSet::GetMapRootIndex() {
return static_cast<int>(RootIndex::kOrderedHashSetMap);
RootIndex OrderedHashSet::GetMapRootIndex() {
return RootIndex::kOrderedHashSetMap;
}
int OrderedHashMap::GetMapRootIndex() {
return static_cast<int>(RootIndex::kOrderedHashMapMap);
RootIndex OrderedHashMap::GetMapRootIndex() {
return RootIndex::kOrderedHashMapMap;
}
int SmallOrderedHashMap::GetMapRootIndex() {
return static_cast<int>(RootIndex::kSmallOrderedHashMapMap);
RootIndex SmallOrderedHashMap::GetMapRootIndex() {
return RootIndex::kSmallOrderedHashMapMap;
}
int SmallOrderedHashSet::GetMapRootIndex() {
return static_cast<int>(RootIndex::kSmallOrderedHashSetMap);
RootIndex SmallOrderedHashSet::GetMapRootIndex() {
return RootIndex::kSmallOrderedHashSetMap;
}
inline Object* OrderedHashMap::ValueAt(int entry) {
......
......@@ -26,7 +26,7 @@ Handle<Derived> OrderedHashTable<Derived, entrysize>::Allocate(
}
int num_buckets = capacity / kLoadFactor;
Handle<FixedArray> backing_store = isolate->factory()->NewFixedArrayWithMap(
static_cast<RootIndex>(Derived::GetMapRootIndex()),
Derived::GetMapRootIndex(),
kHashTableStartIndex + num_buckets + (capacity * kEntrySize), pretenure);
Handle<Derived> table = Handle<Derived>::cast(backing_store);
for (int i = 0; i < num_buckets; ++i) {
......
......@@ -232,7 +232,7 @@ class OrderedHashSet : public OrderedHashTable<OrderedHashSet, 1> {
Handle<OrderedHashSet> table,
GetKeysConversion convert);
static HeapObject* GetEmpty(ReadOnlyRoots ro_roots);
static inline int GetMapRootIndex();
static inline RootIndex GetMapRootIndex();
static inline bool Is(Handle<HeapObject> table);
};
......@@ -250,7 +250,7 @@ class OrderedHashMap : public OrderedHashTable<OrderedHashMap, 2> {
static Object* GetHash(Isolate* isolate, Object* key);
static HeapObject* GetEmpty(ReadOnlyRoots ro_roots);
static inline int GetMapRootIndex();
static inline RootIndex GetMapRootIndex();
static inline bool Is(Handle<HeapObject> table);
static const int kValueOffset = 1;
......@@ -552,7 +552,7 @@ class SmallOrderedHashSet : public SmallOrderedHashTable<SmallOrderedHashSet> {
Handle<SmallOrderedHashSet> table,
Handle<Object> key);
static inline bool Is(Handle<HeapObject> table);
static inline int GetMapRootIndex();
static inline RootIndex GetMapRootIndex();
};
class SmallOrderedHashMap : public SmallOrderedHashTable<SmallOrderedHashMap> {
......@@ -573,7 +573,7 @@ class SmallOrderedHashMap : public SmallOrderedHashTable<SmallOrderedHashMap> {
Handle<Object> key,
Handle<Object> value);
static inline bool Is(Handle<HeapObject> table);
static inline int GetMapRootIndex();
static inline RootIndex GetMapRootIndex();
};
// TODO(gsathya): Rename this to OrderedHashTable, after we rename
......
......@@ -42,7 +42,7 @@ class StringTableShape : public BaseShape<StringTableKey*> {
static inline Handle<Object> AsHandle(Isolate* isolate, Key key);
static inline int GetMapRootIndex();
static inline RootIndex GetMapRootIndex();
static const int kPrefixSize = 0;
static const int kEntrySize = 1;
......
......@@ -324,7 +324,7 @@ namespace internal {
// Declare all the root indices. This defines the root list order.
// clang-format off
enum class RootIndex {
enum class RootIndex : uint16_t {
#define DECL(type, name, CamelName) k##CamelName,
ROOT_LIST(DECL)
#undef DECL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment