Commit a5bde585 authored by ishell@chromium.org's avatar ishell@chromium.org

Dictionary::SetEntry() and Dictionary::AddEntry() handlified.

R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20981 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent fd02e122
......@@ -1467,7 +1467,7 @@ class DictionaryElementsAccessor
DisallowHeapAllocation no_gc;
// Remove elements that should be deleted.
int removed_entries = 0;
Object* the_hole_value = isolate->heap()->the_hole_value();
Handle<Object> the_hole_value = isolate->factory()->the_hole_value();
for (int i = 0; i < capacity; i++) {
Object* key = dict->KeyAt(i);
if (key->IsNumber()) {
......
......@@ -6586,16 +6586,16 @@ bool AccessorPair::prohibits_overwriting() {
template<typename Derived, typename Shape, typename Key>
void Dictionary<Derived, Shape, Key>::SetEntry(int entry,
Object* key,
Object* value) {
Handle<Object> key,
Handle<Object> value) {
SetEntry(entry, key, value, PropertyDetails(Smi::FromInt(0)));
}
template<typename Derived, typename Shape, typename Key>
void Dictionary<Derived, Shape, Key>::SetEntry(int entry,
Object* key,
Object* value,
Handle<Object> key,
Handle<Object> value,
PropertyDetails details) {
ASSERT(!key->IsName() ||
details.IsDeleted() ||
......@@ -6603,8 +6603,8 @@ void Dictionary<Derived, Shape, Key>::SetEntry(int entry,
int index = DerivedHashTable::EntryToIndex(entry);
DisallowHeapAllocation no_gc;
WriteBarrierMode mode = FixedArray::GetWriteBarrierMode(no_gc);
FixedArray::set(index, key, mode);
FixedArray::set(index+1, value, mode);
FixedArray::set(index, *key, mode);
FixedArray::set(index+1, *value, mode);
FixedArray::set(index+2, details.AsSmi());
}
......@@ -6705,7 +6705,7 @@ MaybeObject* ObjectHashTableShape::AsObject(Heap* heap, Object* key) {
Handle<ObjectHashTable> ObjectHashTable::Shrink(
Handle<ObjectHashTable> table, Handle<Object> key) {
return HashTable_::Shrink(table, *key);
return DerivedHashTable::Shrink(table, *key);
}
......
......@@ -692,7 +692,7 @@ void JSObject::SetNormalizedProperty(Handle<JSObject> object,
// Please note we have to update the property details.
property_dictionary->DetailsAtPut(entry, details);
} else {
property_dictionary->SetEntry(entry, *name, *value, details);
property_dictionary->SetEntry(entry, name, value, details);
}
}
......@@ -1932,7 +1932,7 @@ void JSObject::AddSlowProperty(Handle<JSObject> object,
int index = dict->NextEnumerationIndex();
PropertyDetails details = PropertyDetails(attributes, NORMAL, index);
dict->SetNextEnumerationIndex(index + 1);
dict->SetEntry(entry, *name, *cell, details);
dict->SetEntry(entry, name, cell, details);
return;
}
Handle<PropertyCell> cell = isolate->factory()->NewPropertyCell(value);
......@@ -14980,18 +14980,6 @@ template Handle<NameDictionary>
Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >::
EnsureCapacity(Handle<NameDictionary>, int, Handle<Name>);
template MaybeObject*
Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
AddEntry(uint32_t, Object*, PropertyDetails, uint32_t);
template MaybeObject*
Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>::
AddEntry(uint32_t, Object*, PropertyDetails, uint32_t);
template MaybeObject*
Dictionary<NameDictionary, NameDictionaryShape, Handle<Name> >::AddEntry(
Handle<Name>, Object*, PropertyDetails, uint32_t);
template
int Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
NumberOfEnumElements();
......@@ -15840,8 +15828,9 @@ Handle<Object> Dictionary<Derived, Shape, Key>::DeleteProperty(
if (details.IsDontDelete() && mode != JSReceiver::FORCE_DELETION) {
return factory->false_value();
}
dictionary->SetEntry(
entry, *factory->the_hole_value(), *factory->the_hole_value());
entry, factory->the_hole_value(), factory->the_hole_value());
dictionary->ElementRemoved();
return factory->true_value();
}
......@@ -15866,7 +15855,8 @@ Handle<Derived> Dictionary<Derived, Shape, Key>::AtPut(
USE(k);
PropertyDetails details = PropertyDetails(NONE, NORMAL, 0);
return AddEntry(dictionary, key, value, details, dictionary->Hash(key));
AddEntry(dictionary, key, value, details, dictionary->Hash(key));
return dictionary;
}
......@@ -15881,52 +15871,37 @@ Handle<Derived> Dictionary<Derived, Shape, Key>::Add(
// Check whether the dictionary should be extended.
dictionary = EnsureCapacity(dictionary, 1, key);
return AddEntry(dictionary, key, value, details, dictionary->Hash(key));
AddEntry(dictionary, key, value, details, dictionary->Hash(key));
return dictionary;
}
// Add a key, value pair to the dictionary.
template<typename Derived, typename Shape, typename Key>
Handle<Derived> Dictionary<Derived, Shape, Key>::AddEntry(
void Dictionary<Derived, Shape, Key>::AddEntry(
Handle<Derived> dictionary,
Key key,
Handle<Object> value,
PropertyDetails details,
uint32_t hash) {
CALL_HEAP_FUNCTION(
dictionary->GetIsolate(),
dictionary->AddEntry(key, *value, details, hash),
Derived);
}
template<typename Derived, typename Shape, typename Key>
MaybeObject* Dictionary<Derived, Shape, Key>::AddEntry(
Key key,
Object* value,
PropertyDetails details,
uint32_t hash) {
// Compute the key object.
Object* k;
{ MaybeObject* maybe_k = Shape::AsObject(this->GetHeap(), key);
if (!maybe_k->ToObject(&k)) return maybe_k;
}
Handle<Object> k = Shape::AsHandle(dictionary->GetIsolate(), key);
uint32_t entry = Dictionary::FindInsertionEntry(hash);
uint32_t entry = dictionary->FindInsertionEntry(hash);
// Insert element at empty or deleted entry
if (!details.IsDeleted() &&
details.dictionary_index() == 0 &&
Shape::kIsEnumerable) {
// Assign an enumeration index to the property and update
// SetNextEnumerationIndex.
int index = NextEnumerationIndex();
int index = dictionary->NextEnumerationIndex();
details = PropertyDetails(details.attributes(), details.type(), index);
SetNextEnumerationIndex(index + 1);
dictionary->SetNextEnumerationIndex(index + 1);
}
SetEntry(entry, k, value, details);
ASSERT((Dictionary::KeyAt(entry)->IsNumber() ||
Dictionary::KeyAt(entry)->IsName()));
DerivedHashTable::ElementAdded();
return this;
dictionary->SetEntry(entry, k, value, details);
ASSERT((dictionary->KeyAt(entry)->IsNumber() ||
dictionary->KeyAt(entry)->IsName()));
dictionary->ElementAdded();
}
......@@ -16002,7 +15977,7 @@ Handle<SeededNumberDictionary> SeededNumberDictionary::Set(
dictionary->DetailsAt(entry).dictionary_index());
Handle<Object> object_key =
SeededNumberDictionaryShape::AsHandle(dictionary->GetIsolate(), key);
dictionary->SetEntry(entry, *object_key, *value, details);
dictionary->SetEntry(entry, object_key, value, details);
return dictionary;
}
......@@ -16015,7 +15990,7 @@ Handle<UnseededNumberDictionary> UnseededNumberDictionary::Set(
if (entry == kNotFound) return AddNumberEntry(dictionary, key, value);
Handle<Object> object_key =
UnseededNumberDictionaryShape::AsHandle(dictionary->GetIsolate(), key);
dictionary->SetEntry(entry, *object_key, *value);
dictionary->SetEntry(entry, object_key, value);
return dictionary;
}
......
......@@ -3822,7 +3822,7 @@ class HashTable: public FixedArray {
}
// Attempt to shrink hash table after removal of key.
static Handle<Derived> Shrink(Handle<Derived> table, Key key);
MUST_USE_RESULT static Handle<Derived> Shrink(Handle<Derived> table, Key key);
// Ensure enough space for n additional elements.
MUST_USE_RESULT static Handle<Derived> EnsureCapacity(
......@@ -3998,7 +3998,9 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
JSObject::DeleteMode mode);
// Attempt to shrink the dictionary after deletion of key.
static inline Handle<Derived> Shrink(Handle<Derived> dictionary, Key key) {
MUST_USE_RESULT static inline Handle<Derived> Shrink(
Handle<Derived> dictionary,
Key key) {
return DerivedHashTable::Shrink(dictionary, key);
}
......@@ -4047,11 +4049,11 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
// Sets the entry to (key, value) pair.
inline void SetEntry(int entry,
Object* key,
Object* value);
Handle<Object> key,
Handle<Object> value);
inline void SetEntry(int entry,
Object* key,
Object* value,
Handle<Object> key,
Handle<Object> value,
PropertyDetails details);
MUST_USE_RESULT static Handle<Derived> Add(
......@@ -4068,11 +4070,7 @@ class Dictionary: public HashTable<Derived, Shape, Key> {
Handle<Object> value);
// Add entry to dictionary.
MUST_USE_RESULT MaybeObject* AddEntry(Key key,
Object* value,
PropertyDetails details,
uint32_t hash);
MUST_USE_RESULT static Handle<Derived> AddEntry(
static void AddEntry(
Handle<Derived> dictionary,
Key key,
Handle<Object> value,
......@@ -4256,7 +4254,8 @@ class ObjectHashTableShape : public BaseShape<Object*> {
class ObjectHashTable: public HashTable<ObjectHashTable,
ObjectHashTableShape,
Object*> {
typedef HashTable<ObjectHashTable, ObjectHashTableShape, Object*> HashTable_;
typedef HashTable<
ObjectHashTable, ObjectHashTableShape, Object*> DerivedHashTable;
public:
static inline ObjectHashTable* cast(Object* obj) {
ASSERT(obj->IsHashTable());
......@@ -4264,8 +4263,9 @@ class ObjectHashTable: public HashTable<ObjectHashTable,
}
// Attempt to shrink hash table after removal of key.
static inline Handle<ObjectHashTable> Shrink(Handle<ObjectHashTable> table,
Handle<Object> key);
MUST_USE_RESULT static inline Handle<ObjectHashTable> Shrink(
Handle<ObjectHashTable> table,
Handle<Object> key);
// Looks up the value associated with the given key. The hole value is
// returned in case the key is not present.
......
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