Commit 9ca2fc30 authored by ishell@chromium.org's avatar ishell@chromium.org

OrderedHashTable::FindEntry() handlified.

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/260313003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21057 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent e9e2f7f8
......@@ -16287,7 +16287,9 @@ Handle<Derived> OrderedHashTable<Derived, Iterator, entrysize>::Rehash(
template<class Derived, class Iterator, int entrysize>
int OrderedHashTable<Derived, Iterator, entrysize>::FindEntry(Object* key) {
int OrderedHashTable<Derived, Iterator, entrysize>::FindEntry(
Handle<Object> key) {
DisallowHeapAllocation no_gc;
ASSERT(!key->IsTheHole());
Object* hash = key->GetHash();
if (hash->IsUndefined()) return kNotFound;
......@@ -16295,7 +16297,7 @@ int OrderedHashTable<Derived, Iterator, entrysize>::FindEntry(Object* key) {
entry != kNotFound;
entry = ChainAt(entry)) {
Object* candidate = KeyAt(entry);
if (candidate->SameValue(key))
if (candidate->SameValue(*key))
return entry;
}
return kNotFound;
......@@ -16350,7 +16352,8 @@ OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::Clear(
Handle<OrderedHashSet> table);
template int
OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::FindEntry(Object* key);
OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::FindEntry(
Handle<Object> key);
template int
OrderedHashTable<OrderedHashSet, JSSetIterator, 1>::AddEntry(int hash);
......@@ -16376,7 +16379,8 @@ OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::Clear(
Handle<OrderedHashMap> table);
template int
OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::FindEntry(Object* key);
OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::FindEntry(
Handle<Object> key);
template int
OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::AddEntry(int hash);
......@@ -16385,14 +16389,14 @@ template void
OrderedHashTable<OrderedHashMap, JSMapIterator, 2>::RemoveEntry(int entry);
bool OrderedHashSet::Contains(Object* key) {
bool OrderedHashSet::Contains(Handle<Object> key) {
return FindEntry(key) != kNotFound;
}
Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table,
Handle<Object> key) {
if (table->FindEntry(*key) != kNotFound) return table;
if (table->FindEntry(key) != kNotFound) return table;
table = EnsureGrowable(table);
......@@ -16405,7 +16409,7 @@ Handle<OrderedHashSet> OrderedHashSet::Add(Handle<OrderedHashSet> table,
Handle<OrderedHashSet> OrderedHashSet::Remove(Handle<OrderedHashSet> table,
Handle<Object> key) {
int entry = table->FindEntry(*key);
int entry = table->FindEntry(key);
if (entry == kNotFound) return table;
table->RemoveEntry(entry);
return Shrink(table);
......@@ -16414,7 +16418,7 @@ Handle<OrderedHashSet> OrderedHashSet::Remove(Handle<OrderedHashSet> table,
Object* OrderedHashMap::Lookup(Handle<Object> key) {
DisallowHeapAllocation no_gc;
int entry = FindEntry(*key);
int entry = FindEntry(key);
if (entry == kNotFound) return GetHeap()->the_hole_value();
return ValueAt(entry);
}
......@@ -16423,7 +16427,7 @@ Object* OrderedHashMap::Lookup(Handle<Object> key) {
Handle<OrderedHashMap> OrderedHashMap::Put(Handle<OrderedHashMap> table,
Handle<Object> key,
Handle<Object> value) {
int entry = table->FindEntry(*key);
int entry = table->FindEntry(key);
if (value->IsTheHole()) {
if (entry == kNotFound) return table;
......
......@@ -4270,7 +4270,7 @@ class OrderedHashTable: public FixedArray {
static Handle<Derived> Clear(Handle<Derived> table);
// Returns kNotFound if the key isn't present.
int FindEntry(Object* key);
int FindEntry(Handle<Object> key);
int NumberOfElements() {
return Smi::cast(get(kNumberOfElementsIndex))->value();
......@@ -4369,7 +4369,7 @@ class OrderedHashSet: public OrderedHashTable<
return reinterpret_cast<OrderedHashSet*>(obj);
}
bool Contains(Object* key);
bool Contains(Handle<Object> key);
static Handle<OrderedHashSet> Add(
Handle<OrderedHashSet> table, Handle<Object> key);
static Handle<OrderedHashSet> Remove(
......
......@@ -1531,7 +1531,7 @@ RUNTIME_FUNCTION(Runtime_SetHas) {
CONVERT_ARG_HANDLE_CHECKED(JSSet, holder, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
Handle<OrderedHashSet> table(OrderedHashSet::cast(holder->table()));
return isolate->heap()->ToBoolean(table->Contains(*key));
return isolate->heap()->ToBoolean(table->Contains(key));
}
......
......@@ -76,7 +76,7 @@ static void TestHashMap(Handle<HashMap> table) {
Handle<JSObject> value = factory->NewJSArray(11);
table = HashMap::Put(table, key, value);
CHECK_EQ(table->NumberOfElements(), i + 1);
CHECK_NE(table->FindEntry(*key), HashMap::kNotFound);
CHECK_NE(table->FindEntry(key), HashMap::kNotFound);
CHECK_EQ(table->Lookup(key), *value);
CHECK(key->GetIdentityHash()->IsSmi());
}
......@@ -86,7 +86,7 @@ static void TestHashMap(Handle<HashMap> table) {
for (int i = 0; i < 100; i++) {
Handle<JSReceiver> key = factory->NewJSArray(7);
CHECK(JSReceiver::GetOrCreateIdentityHash(key)->IsSmi());
CHECK_EQ(table->FindEntry(*key), HashMap::kNotFound);
CHECK_EQ(table->FindEntry(key), HashMap::kNotFound);
CHECK_EQ(table->Lookup(key), CcTest::heap()->the_hole_value());
CHECK(key->GetIdentityHash()->IsSmi());
}
......@@ -183,7 +183,7 @@ static void TestHashSetCausesGC(Handle<HashSet> table) {
// Calling Contains() should not cause GC ever.
int gc_count = isolate->heap()->gc_count();
CHECK(!table->Contains(*key));
CHECK(!table->Contains(key));
CHECK(gc_count == isolate->heap()->gc_count());
// Calling Remove() will not cause GC in this case.
......
......@@ -71,13 +71,13 @@ TEST(Set) {
Handle<Map> map = factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
Handle<JSObject> obj = factory->NewJSObjectFromMap(map);
CHECK(!ordered_set->Contains(*obj));
CHECK(!ordered_set->Contains(obj));
ordered_set = OrderedHashSet::Add(ordered_set, obj);
CHECK_EQ(1, ordered_set->NumberOfElements());
CHECK(ordered_set->Contains(*obj));
CHECK(ordered_set->Contains(obj));
ordered_set = OrderedHashSet::Remove(ordered_set, obj);
CHECK_EQ(0, ordered_set->NumberOfElements());
CHECK(!ordered_set->Contains(*obj));
CHECK(!ordered_set->Contains(obj));
// Test for collisions/chaining
Handle<JSObject> obj1 = factory->NewJSObjectFromMap(map);
......@@ -87,9 +87,9 @@ TEST(Set) {
Handle<JSObject> obj3 = factory->NewJSObjectFromMap(map);
ordered_set = OrderedHashSet::Add(ordered_set, obj3);
CHECK_EQ(3, ordered_set->NumberOfElements());
CHECK(ordered_set->Contains(*obj1));
CHECK(ordered_set->Contains(*obj2));
CHECK(ordered_set->Contains(*obj3));
CHECK(ordered_set->Contains(obj1));
CHECK(ordered_set->Contains(obj2));
CHECK(ordered_set->Contains(obj3));
// Test iteration
CheckIterResultObject(
......@@ -107,11 +107,11 @@ TEST(Set) {
ordered_set = OrderedHashSet::Add(ordered_set, obj);
Handle<JSObject> obj4 = factory->NewJSObjectFromMap(map);
ordered_set = OrderedHashSet::Add(ordered_set, obj4);
CHECK(ordered_set->Contains(*obj));
CHECK(ordered_set->Contains(*obj1));
CHECK(ordered_set->Contains(*obj2));
CHECK(ordered_set->Contains(*obj3));
CHECK(ordered_set->Contains(*obj4));
CHECK(ordered_set->Contains(obj));
CHECK(ordered_set->Contains(obj1));
CHECK(ordered_set->Contains(obj2));
CHECK(ordered_set->Contains(obj3));
CHECK(ordered_set->Contains(obj4));
CHECK_EQ(5, ordered_set->NumberOfElements());
CHECK_EQ(0, ordered_set->NumberOfDeletedElements());
CHECK_EQ(4, ordered_set->NumberOfBuckets());
......
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