Reviewers: Yang,

Message:
PTAL #5

Description:
Dictionary::AtPut() handlified.

Please review this at https://codereview.chromium.org/249883003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+47, -31 lines):
  M src/objects.h
  M src/objects.cc
  M src/objects-inl.h


Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 2e23167fad0d728a2dff10823f0a8f5885419e7c..bc201320605a0349aa93ec489e1eb08df7be8a1b 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -6672,6 +6672,13 @@ MaybeObject* NameDictionaryShape::AsObject(Heap* heap, Name* key) {
 }


+Handle<Object> NameDictionaryShape::AsHandle(Isolate* isolate, Name* key) {
+  ASSERT(key->IsUniqueName());
+  // TODO(ishell): Convert Name* to Handle<Name> to avoid re-wrapping here.
+  return handle(key, isolate);
+}
+
+
 bool ObjectHashTableShape::IsMatch(Object* key, Object* other) {
   return key->SameValue(other);
 }
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 0df564b9eaf5ced4671579b9d8fa196a3e43daef..86baab160370c9e06b21d466122d15213f35de64 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -14898,13 +14898,13 @@ template Handle<NameDictionary>
 Dictionary<NameDictionary, NameDictionaryShape, Name*>::
     New(Isolate* isolate, int n, PretenureFlag pretenure);

-template MaybeObject*
+template Handle<SeededNumberDictionary>
 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
-    AtPut(uint32_t, Object*);
+    AtPut(Handle<SeededNumberDictionary>, uint32_t, Handle<Object>);

-template MaybeObject*
+template Handle<UnseededNumberDictionary>
Dictionary<UnseededNumberDictionary, UnseededNumberDictionaryShape, uint32_t>::
-    AtPut(uint32_t, Object*);
+    AtPut(Handle<UnseededNumberDictionary>, uint32_t, Handle<Object>);

 template Object*
 Dictionary<SeededNumberDictionary, SeededNumberDictionaryShape, uint32_t>::
@@ -15937,29 +15937,25 @@ Object* Dictionary<Derived, Shape, Key>::DeleteProperty(


 template<typename Derived, typename Shape, typename Key>
-MaybeObject* Dictionary<Derived, Shape, Key>::AtPut(Key key, Object* value) {
-  int entry = this->FindEntry(key);
+Handle<Derived> Dictionary<Derived, Shape, Key>::AtPut(
+    Handle<Derived> dictionary, Key key, Handle<Object> 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<Object> 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));
 }


@@ -15983,6 +15979,19 @@ MaybeObject* Dictionary<Derived, Shape, Key>::Add(

 // Add a key, value pair to the dictionary.
 template<typename Derived, typename Shape, typename Key>
+Handle<Derived> 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,
@@ -16063,10 +16072,7 @@ Handle<SeededNumberDictionary> SeededNumberDictionary::AtNumberPut(
     uint32_t key,
     Handle<Object> value) {
   dictionary->UpdateMaxNumberKey(key);
-  CALL_HEAP_FUNCTION(
-      dictionary->GetIsolate(),
-      dictionary->AtPut(key, *value),
-      SeededNumberDictionary);
+  return AtPut(dictionary, key, value);
 }


@@ -16074,10 +16080,7 @@ Handle<UnseededNumberDictionary> UnseededNumberDictionary::AtNumberPut(
     Handle<UnseededNumberDictionary> dictionary,
     uint32_t key,
     Handle<Object> value) {
-  CALL_HEAP_FUNCTION(
-      dictionary->GetIsolate(),
-      dictionary->AtPut(key, *value),
-      UnseededNumberDictionary);
+  return AtPut(dictionary, key, value);
 }


Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 85807ee34629df866445e9e7c0163706367a88c3..37eb1393ff2b13f4ca3dc19bed21669b79fead40 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -4095,13 +4095,22 @@ class Dictionary: public HashTable<Derived, Shape, Key> {

  protected:
   // Generic at put operation.
-  MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value);
+  MUST_USE_RESULT static Handle<Derived> AtPut(
+      Handle<Derived> dictionary,
+      Key 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(
+      Handle<Derived> dictionary,
+      Key key,
+      Handle<Object> 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<Name*> {
   static inline uint32_t HashForObject(Name* key, Object* object);
   MUST_USE_RESULT static inline MaybeObject* AsObject(Heap* heap,
                                                       Name* key);
+  static inline Handle<Object> 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<Object> 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


--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to