Minor cleanup in element handling
authorverwaest <verwaest@chromium.org>
Thu, 18 Jun 2015 12:56:48 +0000 (05:56 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 18 Jun 2015 12:57:03 +0000 (12:57 +0000)
BUG=v8:4137
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#29114}

src/objects.cc

index 3137f3e..b727905 100644 (file)
@@ -12511,23 +12511,24 @@ void JSObject::AddFastElement(Handle<JSObject> object, uint32_t index,
     }
   }
 
-  // Convert to fast double elements if appropriate.
-  if (object->HasFastSmiElements() && !value->IsSmi() && value->IsNumber()) {
-    // Consider fixing the boilerplate as well if we have one.
-    ElementsKind to_kind = IsHoleyElementsKind(object->GetElementsKind())
-                               ? FAST_HOLEY_DOUBLE_ELEMENTS
-                               : FAST_DOUBLE_ELEMENTS;
+  if (object->HasFastSmiElements() && !value->IsSmi()) {
+    // Convert to fast double elements if appropriate.
+    if (value->IsNumber()) {
+      // Consider fixing the boilerplate as well if we have one.
+      ElementsKind to_kind = IsHoleyElementsKind(object->GetElementsKind())
+                                 ? FAST_HOLEY_DOUBLE_ELEMENTS
+                                 : FAST_DOUBLE_ELEMENTS;
 
-    UpdateAllocationSite(object, to_kind);
+      UpdateAllocationSite(object, to_kind);
 
-    SetFastDoubleElementsCapacityAndLength(object, new_capacity, array_length);
-    FixedDoubleArray::cast(object->elements())->set(index, value->Number());
-    JSObject::ValidateElements(object);
-    return;
-  }
+      SetFastDoubleElementsCapacityAndLength(object, new_capacity,
+                                             array_length);
+      FixedDoubleArray::cast(object->elements())->set(index, value->Number());
+      JSObject::ValidateElements(object);
+      return;
+    }
 
-  // Change elements kind from Smi-only to generic FAST if necessary.
-  if (object->HasFastSmiElements() && !value->IsSmi()) {
+    // Change elements kind from Smi-only to generic FAST if necessary.
     ElementsKind kind = object->HasFastHoleyElements()
         ? FAST_HOLEY_ELEMENTS
         : FAST_ELEMENTS;
@@ -12539,7 +12540,14 @@ void JSObject::AddFastElement(Handle<JSObject> object, uint32_t index,
   }
 
   // Increase backing store capacity if that's been decided previously.
-  if (new_capacity != capacity) {
+  // Otherwise, set the new element and length.
+  if (new_capacity == capacity) {
+    DCHECK(object->elements()->IsFixedArray());
+    backing_store->set(index, *value);
+    if (must_update_array_length) {
+      Handle<JSArray>::cast(object)->set_length(Smi::FromInt(array_length));
+    }
+  } else {
     SetFastElementsCapacitySmiMode smi_mode =
         value->IsSmi() && object->HasFastSmiElements()
             ? kAllowSmiElements
@@ -12549,14 +12557,6 @@ void JSObject::AddFastElement(Handle<JSObject> object, uint32_t index,
                                          smi_mode);
     new_elements->set(index, *value);
     JSObject::ValidateElements(object);
-    return;
-  }
-
-  // Finally, set the new element and length.
-  DCHECK(object->elements()->IsFixedArray());
-  backing_store->set(index, *value);
-  if (must_update_array_length) {
-    Handle<JSArray>::cast(object)->set_length(Smi::FromInt(array_length));
   }
 }