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