Reviewers: Igor Sheludko,

Message:
PTAL

Description:
Introduce an abstraction to write to a field.

BUG=

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

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

Affected files (+28, -46 lines):
  M src/objects.h
  M src/objects.cc


Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index c53c205be1524c2acbe451b734c4d95860d2cef6..1ef47c9ca305020157f328d763e1ad5325891892 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -1904,22 +1904,7 @@ void JSObject::AddFastProperty(Handle<JSObject> object,
     }
   }

-  JSObject::MigrateToMap(object, new_map);
-
-  PropertyDetails details = new_map->GetLastDescriptorDetails();
-  if (details.type() != FIELD) return;
-
-  Representation representation = details.representation();
-  int index = details.field_index();
-
-  if (representation.IsDouble()) {
-    // Nothing more to be done.
-    if (value->IsUninitialized()) return;
-    HeapNumber* box = HeapNumber::cast(object->RawFastPropertyAt(index));
-    box->set_value(value->Number());
-  } else {
-    object->FastPropertyAtPut(index, *value);
-  }
+  JSObject::MigrateToNewProperty(object, new_map, value);
 }


@@ -3952,31 +3937,37 @@ MaybeHandle<Object> JSObject::SetPropertyUsingTransition(
         field_representation, field_type, FORCE_FIELD);
   }

-  JSObject::MigrateToMap(object, transition_map);
+  JSObject::MigrateToNewProperty(object, transition_map, value);
+  return value;
+}

-  // Reload.
-  descriptors = handle(transition_map->instance_descriptors());
-  details = descriptors->GetDetails(descriptor);

-  if (details.type() != FIELD) return value;
+void JSObject::MigrateToNewProperty(Handle<JSObject> object,
+                                    Handle<Map> map,
+                                    Handle<Object> value) {
+  JSObject::MigrateToMap(object, map);
+  if (map->GetLastDescriptorDetails().type() != FIELD) return;
+  object->WriteToField(map->LastAdded(), *value);
+}
+

-  int field_index = descriptors->GetFieldIndex(descriptor);
+void JSObject::WriteToField(int descriptor, Object* value) {
+  DescriptorArray* desc = map()->instance_descriptors();
+  PropertyDetails details = desc->GetDetails(descriptor);
+  int field_index = desc->GetFieldIndex(descriptor);
   if (details.representation().IsDouble()) {
     // Nothing more to be done.
-    if (value->IsUninitialized()) return value;
- HeapNumber* box = HeapNumber::cast(object->RawFastPropertyAt(field_index));
+    if (value->IsUninitialized()) return;
+    HeapNumber* box = HeapNumber::cast(RawFastPropertyAt(field_index));
     box->set_value(value->Number());
   } else {
-    object->FastPropertyAtPut(field_index, *value);
+    FastPropertyAtPut(field_index, value);
   }
-
-  return value;
 }


 static void SetPropertyToField(LookupResult* lookup,
                                Handle<Object> value) {
-  Representation representation = lookup->representation();
   if (lookup->type() == CONSTANT || !lookup->CanHoldValue(value)) {
     Representation field_representation = value->OptimalRepresentation();
     Handle<HeapType> field_type = value->OptimalType(
@@ -3985,20 +3976,8 @@ static void SetPropertyToField(LookupResult* lookup,
                                             lookup->GetDescriptorIndex(),
field_representation, field_type,
                                             FORCE_FIELD);
- DescriptorArray* desc = lookup->holder()->map()->instance_descriptors();
-    int descriptor = lookup->GetDescriptorIndex();
-    representation = desc->GetDetails(descriptor).representation();
   }
-
-  if (representation.IsDouble()) {
- HeapNumber* storage = HeapNumber::cast(lookup->holder()->RawFastPropertyAt(
-        lookup->GetFieldIndex().field_index()));
-    storage->set_value(value->Number());
-    return;
-  }
-
-  lookup->holder()->FastPropertyAtPut(
-      lookup->GetFieldIndex().field_index(), *value);
+  lookup->holder()->WriteToField(lookup->GetDescriptorIndex(), *value);
 }


@@ -4028,9 +4007,7 @@ static void ConvertAndSetLocalProperty(LookupResult* lookup,
     JSObject::MigrateToMap(object, new_map);
   }

-  DescriptorArray* descriptors = object->map()->instance_descriptors();
-  int index = descriptors->GetDetails(descriptor_index).field_index();
-  object->FastPropertyAtPut(index, *value);
+  object->WriteToField(descriptor_index, *value);
 }


@@ -5226,8 +5203,7 @@ Handle<Object> JSObject::SetHiddenPropertiesHashTable(Handle<JSObject> object, if (descriptors->GetKey(sorted_index) == isolate->heap()->hidden_string()
           && sorted_index < object->map()->NumberOfOwnDescriptors()) {
         ASSERT(descriptors->GetType(sorted_index) == FIELD);
-        object->FastPropertyAtPut(descriptors->GetFieldIndex(sorted_index),
-                                  *value);
+        object->WriteToField(sorted_index, *value);
         return object;
       }
     }
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index f4d2fc892d205f7aa920e0da61be3dc49a2f8a91..d0d67357a45dfd23fbc6e88548a832cd7db0fe43 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -2614,6 +2614,7 @@ class JSObject: public JSReceiver {
                                        int index);
   inline Object* RawFastPropertyAt(int index);
   inline void FastPropertyAtPut(int index, Object* value);
+  void WriteToField(int descriptor, Object* value);

   // Access to in object properties.
   inline int GetInObjectPropertyOffset(int index);
@@ -2902,6 +2903,11 @@ class JSObject: public JSReceiver {
                               ValueType value_type,
                               TransitionFlag flag);

+  static void MigrateToNewProperty(Handle<JSObject> object,
+                                   Handle<Map> transition,
+                                   Handle<Object> value);
+
+
   // Add a property to a slow-case object.
   static void AddSlowProperty(Handle<JSObject> object,
                               Handle<Name> name,


--
--
v8-dev mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to