Commit e3801132 authored by Sathya Gunasekaran's avatar Sathya Gunasekaran Committed by Commit Bot

[Collections] Don't templatize OrderedHashTable::Get

OrderedHashSet doesn't need a ::Get, so we can move it to
OrderedHashMap.

Bug: v8:5717
Change-Id: I9606d8c4608473f9daecf8a87b4dd2e3b9570246
Reviewed-on: https://chromium-review.googlesource.com/522348Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Commit-Queue: Sathya Gunasekaran <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45740}
parent fa0d5be1
......@@ -1589,10 +1589,8 @@ ExternalReference ExternalReference::search_string_raw(Isolate* isolate) {
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f)));
}
template <typename CollectionType, int entrysize>
ExternalReference ExternalReference::orderedhashtable_get_raw(
Isolate* isolate) {
auto f = OrderedHashTable<CollectionType, entrysize>::Get;
ExternalReference ExternalReference::orderedhashmap_get_raw(Isolate* isolate) {
auto f = OrderedHashMap::Get;
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f)));
}
......@@ -1633,11 +1631,6 @@ ExternalReference::search_string_raw<const uc16, const uint8_t>(Isolate*);
template ExternalReference
ExternalReference::search_string_raw<const uc16, const uc16>(Isolate*);
template ExternalReference
ExternalReference::orderedhashtable_get_raw<OrderedHashMap, 2>(Isolate*);
template ExternalReference
ExternalReference::orderedhashtable_get_raw<OrderedHashSet, 1>(Isolate*);
template ExternalReference
ExternalReference::orderedhashtable_has_raw<OrderedHashMap, 2>(Isolate*);
template ExternalReference
......
......@@ -1024,8 +1024,7 @@ class ExternalReference BASE_EMBEDDED {
template <typename SubjectChar, typename PatternChar>
static ExternalReference search_string_raw(Isolate* isolate);
template <typename CollectionType, int entrysize>
static ExternalReference orderedhashtable_get_raw(Isolate* isolate);
static ExternalReference orderedhashmap_get_raw(Isolate* isolate);
template <typename CollectionType, int entrysize>
static ExternalReference orderedhashtable_has_raw(Isolate* isolate);
......
......@@ -19,7 +19,6 @@ class CollectionsBuiltinsAssembler : public CodeStubAssembler {
protected:
Node* AllocateJSMap(Node* js_map_function);
template <typename CollectionType, int entrysize>
Node* CallGetRaw(Node* const table, Node* const key);
template <typename CollectionType, int entrysize>
Node* CallHasRaw(Node* const table, Node* const key);
......@@ -156,12 +155,10 @@ TF_BUILTIN(MapConstructor, CollectionsBuiltinsAssembler) {
Return(var_result.value());
}
template <typename CollectionType, int entrysize>
Node* CollectionsBuiltinsAssembler::CallGetRaw(Node* const table,
Node* const key) {
Node* const function_addr = ExternalConstant(
ExternalReference::orderedhashtable_get_raw<CollectionType, entrysize>(
isolate()));
Node* const function_addr =
ExternalConstant(ExternalReference::orderedhashmap_get_raw(isolate()));
Node* const isolate_ptr =
ExternalConstant(ExternalReference::isolate_address(isolate()));
......@@ -202,7 +199,7 @@ TF_BUILTIN(MapGet, CollectionsBuiltinsAssembler) {
ThrowIfNotInstanceType(context, receiver, JS_MAP_TYPE, "Map.prototype.get");
Node* const table = LoadObjectField(receiver, JSMap::kTableOffset);
Return(CallGetRaw<OrderedHashMap, 2>(table, key));
Return(CallGetRaw(table, key));
}
TF_BUILTIN(MapHas, CollectionsBuiltinsAssembler) {
......
......@@ -271,12 +271,8 @@ void ExternalReferenceTable::AddReferences(Isolate* isolate) {
Add(ExternalReference::search_string_raw<const uc16, const uc16>(isolate)
.address(),
"search_string_raw<1-byte, 2-byte>");
Add(ExternalReference::orderedhashtable_get_raw<OrderedHashMap, 2>(isolate)
.address(),
"orderedhashtable_get_raw<OrderedHashMap, 2>");
Add(ExternalReference::orderedhashtable_get_raw<OrderedHashSet, 1>(isolate)
.address(),
"orderedhashtable_get_raw<OrderedHashSet, 1>");
Add(ExternalReference::orderedhashmap_get_raw(isolate).address(),
"orderedhashmap_get_raw");
Add(ExternalReference::orderedhashtable_has_raw<OrderedHashMap, 2>(isolate)
.address(),
"orderedhashtable_has_raw<OrderedHashMap, 2>");
......
......@@ -1380,6 +1380,11 @@ int HeapNumber::get_sign() {
return READ_INT_FIELD(this, kExponentOffset) & kSignMask;
}
inline Object* OrderedHashMap::ValueAt(int entry) {
DCHECK_LT(entry, this->UsedCapacity());
return get(EntryToIndex(entry) + kValueOffset);
}
ACCESSORS(JSReceiver, properties, FixedArray, kPropertiesOffset)
......
......@@ -18764,6 +18764,7 @@ template <class Derived, int entrysize>
Object* OrderedHashTable<Derived, entrysize>::HasKey(Isolate* isolate,
Derived* table,
Object* key) {
DCHECK(table->IsOrderedHashTable());
DisallowHeapAllocation no_gc;
int entry = table->KeyToFirstEntry(isolate, key);
// Walk the chain in the bucket to find the key.
......@@ -18775,23 +18776,6 @@ Object* OrderedHashTable<Derived, entrysize>::HasKey(Isolate* isolate,
return isolate->heap()->false_value();
}
template <class Derived, int entrysize>
Object* OrderedHashTable<Derived, entrysize>::Get(Isolate* isolate,
Derived* table, Object* key) {
DCHECK(table->IsOrderedHashTable());
DisallowHeapAllocation no_gc;
int entry = table->KeyToFirstEntry(isolate, key);
// Walk the chain in the bucket to find the key.
while (entry != kNotFound) {
Object* candidate_key = table->KeyAt(entry);
if (candidate_key->SameValueZero(key)) {
return table->ValueAt(entry);
}
entry = table->NextChainEntry(entry);
}
return isolate->heap()->undefined_value();
}
Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table,
Handle<Object> key) {
int hash = Object::GetOrCreateHash(table->GetIsolate(), key)->value();
......@@ -18891,6 +18875,22 @@ Handle<Derived> OrderedHashTable<Derived, entrysize>::Rehash(
return new_table;
}
Object* OrderedHashMap::Get(Isolate* isolate, OrderedHashMap* table,
Object* key) {
DCHECK(table->IsOrderedHashMap());
DisallowHeapAllocation no_gc;
int entry = table->KeyToFirstEntry(isolate, key);
// Walk the chain in the bucket to find the key.
while (entry != kNotFound) {
Object* candidate_key = table->KeyAt(entry);
if (candidate_key->SameValueZero(key)) {
return table->ValueAt(entry);
}
entry = table->NextChainEntry(entry);
}
return isolate->heap()->undefined_value();
}
template Handle<OrderedHashSet> OrderedHashTable<OrderedHashSet, 1>::Allocate(
Isolate* isolate, int capacity, PretenureFlag pretenure);
......@@ -18906,10 +18906,6 @@ template Handle<OrderedHashSet> OrderedHashTable<OrderedHashSet, 1>::Clear(
template Object* OrderedHashTable<OrderedHashSet, 1>::HasKey(
Isolate* isolate, OrderedHashSet* table, Object* key);
template Object* OrderedHashTable<OrderedHashSet, 1>::Get(Isolate* isolate,
OrderedHashSet* table,
Object* key);
template Handle<OrderedHashMap> OrderedHashTable<OrderedHashMap, 2>::Allocate(
Isolate* isolate, int capacity, PretenureFlag pretenure);
......@@ -18925,9 +18921,6 @@ template Handle<OrderedHashMap> OrderedHashTable<OrderedHashMap, 2>::Clear(
template Object* OrderedHashTable<OrderedHashMap, 2>::HasKey(
Isolate* isolate, OrderedHashMap* table, Object* key);
template Object* OrderedHashTable<OrderedHashMap, 2>::Get(Isolate* isolate,
OrderedHashMap* table,
Object* key);
template <>
Handle<SmallOrderedHashSet>
SmallOrderedHashTable<SmallOrderedHashSet>::Allocate(Isolate* isolate,
......
......@@ -401,10 +401,6 @@ class OrderedHashTable : public FixedArray {
// Returns a true if the OrderedHashTable contains the key
static Object* HasKey(Isolate* isolate, Derived* table, Object* key);
// Returns a value if the OrderedHashTable contains the key,
// otherwise returns undefined.
static Object* Get(Isolate* isolate, Derived* table, Object* key);
int NumberOfElements() {
return Smi::cast(get(kNumberOfElementsIndex))->value();
}
......@@ -460,11 +456,6 @@ class OrderedHashTable : public FixedArray {
return get(EntryToIndex(entry));
}
Object* ValueAt(int entry) {
DCHECK_LT(entry, this->UsedCapacity());
return get(EntryToIndex(entry) + Derived::kValueOffset);
}
bool IsObsolete() { return !get(kNextTableIndex)->IsSmi(); }
// The next newer table. This is only valid if the table is obsolete.
......@@ -545,13 +536,17 @@ class OrderedHashSet : public OrderedHashTable<OrderedHashSet, 1> {
Handle<Object> value);
static Handle<FixedArray> ConvertToKeysArray(Handle<OrderedHashSet> table,
GetKeysConversion convert);
static const int kValueOffset = 0;
};
class OrderedHashMap : public OrderedHashTable<OrderedHashMap, 2> {
public:
DECLARE_CAST(OrderedHashMap)
// Returns a value if the OrderedHashMap contains the key, otherwise
// returns undefined.
static Object* Get(Isolate* isolate, OrderedHashMap* table, Object* key);
Object* ValueAt(int entry);
static const int kValueOffset = 1;
};
......
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