From 34e59aa239af709330ffa6b8126750c468522fad Mon Sep 17 00:00:00 2001 From: "ishell@chromium.org" Date: Thu, 24 Apr 2014 10:47:13 +0000 Subject: [PATCH] Dictionary::AtPut() handlified. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/249883003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20935 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/objects-inl.h | 7 ++++++ src/objects.cc | 55 +++++++++++++++++++++++++---------------------- src/objects.h | 16 +++++++++----- 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/objects-inl.h b/src/objects-inl.h index 2e23167fad..bc20132060 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -6672,6 +6672,13 @@ MaybeObject* NameDictionaryShape::AsObject(Heap* heap, Name* key) { } +Handle NameDictionaryShape::AsHandle(Isolate* isolate, Name* key) { + ASSERT(key->IsUniqueName()); + // TODO(ishell): Convert Name* to Handle to avoid re-wrapping here. + return handle(key, isolate); +} + + bool ObjectHashTableShape::IsMatch(Object* key, Object* other) { return key->SameValue(other); } diff --git a/src/objects.cc b/src/objects.cc index 34fdf25343..a1c8a90f0e 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -14902,13 +14902,13 @@ template Handle Dictionary:: New(Isolate* isolate, int n, PretenureFlag pretenure); -template MaybeObject* +template Handle Dictionary:: - AtPut(uint32_t, Object*); + AtPut(Handle, uint32_t, Handle); -template MaybeObject* +template Handle Dictionary:: - AtPut(uint32_t, Object*); + AtPut(Handle, uint32_t, Handle); template Object* Dictionary:: @@ -15943,29 +15943,25 @@ Object* Dictionary::DeleteProperty( template -MaybeObject* Dictionary::AtPut(Key key, Object* value) { - int entry = this->FindEntry(key); +Handle Dictionary::AtPut( + Handle dictionary, Key key, Handle value) { + int entry = dictionary->FindEntry(key); // If the entry is present set the value; if (entry != Dictionary::kNotFound) { - ValueAtPut(entry, value); - return this; + dictionary->ValueAtPut(entry, *value); + return dictionary; } // Check whether the dictionary should be extended. - Object* obj; - { MaybeObject* maybe_obj = EnsureCapacity(1, key); - if (!maybe_obj->ToObject(&obj)) return maybe_obj; - } + dictionary = EnsureCapacity(dictionary, 1, key); - Object* k; - { MaybeObject* maybe_k = Shape::AsObject(this->GetHeap(), key); - if (!maybe_k->ToObject(&k)) return maybe_k; - } + Handle k = Shape::AsHandle(dictionary->GetIsolate(), key); + // TODO(ishell): Figure out if it is necessary to call AsHandle() here. + USE(k); PropertyDetails details = PropertyDetails(NONE, NORMAL, 0); - return Dictionary::cast(obj)->AddEntry( - key, value, details, Dictionary::Hash(key)); + return AddEntry(dictionary, key, value, details, dictionary->Hash(key)); } @@ -15988,6 +15984,19 @@ MaybeObject* Dictionary::Add( // Add a key, value pair to the dictionary. +template +Handle Dictionary::AddEntry( + Handle dictionary, + Key key, + Handle value, + PropertyDetails details, + uint32_t hash) { + CALL_HEAP_FUNCTION( + dictionary->GetIsolate(), + dictionary->AddEntry(key, *value, details, hash), + Derived); +} + template MaybeObject* Dictionary::AddEntry( Key key, @@ -16069,10 +16078,7 @@ Handle SeededNumberDictionary::AtNumberPut( uint32_t key, Handle value) { dictionary->UpdateMaxNumberKey(key); - CALL_HEAP_FUNCTION( - dictionary->GetIsolate(), - dictionary->AtPut(key, *value), - SeededNumberDictionary); + return AtPut(dictionary, key, value); } @@ -16080,10 +16086,7 @@ Handle UnseededNumberDictionary::AtNumberPut( Handle dictionary, uint32_t key, Handle value) { - CALL_HEAP_FUNCTION( - dictionary->GetIsolate(), - dictionary->AtPut(key, *value), - UnseededNumberDictionary); + return AtPut(dictionary, key, value); } diff --git a/src/objects.h b/src/objects.h index 85807ee346..37eb1393ff 100644 --- a/src/objects.h +++ b/src/objects.h @@ -4095,13 +4095,22 @@ class Dictionary: public HashTable { protected: // Generic at put operation. - MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); + MUST_USE_RESULT static Handle AtPut( + Handle dictionary, + Key key, + Handle value); // Add entry to dictionary. MUST_USE_RESULT MaybeObject* AddEntry(Key key, Object* value, PropertyDetails details, uint32_t hash); + MUST_USE_RESULT static Handle AddEntry( + Handle dictionary, + Key key, + Handle value, + PropertyDetails details, + uint32_t hash); // Generate new enumeration indices to avoid enumeration index overflow. MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); @@ -4117,6 +4126,7 @@ class NameDictionaryShape : public BaseShape { static inline uint32_t HashForObject(Name* key, Object* object); MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap, Name* key); + static inline Handle AsHandle(Isolate* isolate, Name* key); static const int kPrefixSize = 2; static const int kEntrySize = 3; static const bool kIsEnumerable = true; @@ -4211,10 +4221,6 @@ class SeededNumberDictionary Handle value, PropertyDetails details); - MUST_USE_RESULT MaybeObject* Set(uint32_t key, - Object* value, - PropertyDetails details); - void UpdateMaxNumberKey(uint32_t key); // If slow elements are required we will never go back to fast-case