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