Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(747)

Unified Diff: src/objects.cc

Issue 1190143002: Minor cleanup in element handling (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 674a7c052526b4b447946c3178df6f97ef18335c..718f35e271b582c84298496bf4c8fcf5c84fa2c8 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -12489,23 +12489,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;
@@ -12517,7 +12518,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
@@ -12527,14 +12535,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));
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698