Commit dee4895d authored by verwaest's avatar verwaest Committed by Commit bot

Cleanup adding elements and in particular dictionary elements

BUG=v8:4137
LOG=n

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

Cr-Commit-Position: refs/heads/master@{#29232}
parent 7f5a2d9e
...@@ -989,11 +989,12 @@ class FastElementsAccessor ...@@ -989,11 +989,12 @@ class FastElementsAccessor
if (length == 0) return; // nothing to do! if (length == 0) return; // nothing to do!
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements); Handle<BackingStore> backing_store = Handle<BackingStore>::cast(elements);
for (int i = 0; i < length; i++) { if (IsFastSmiElementsKind(KindTraits::Kind)) {
DCHECK((!IsFastSmiElementsKind(KindTraits::Kind) || for (int i = 0; i < length; i++) {
BackingStore::get(backing_store, i)->IsSmi()) || DCHECK(BackingStore::get(backing_store, i)->IsSmi() ||
(IsFastHoleyElementsKind(KindTraits::Kind) == (IsFastHoleyElementsKind(KindTraits::Kind) &&
backing_store->is_the_hole(i))); backing_store->is_the_hole(i)));
}
} }
#endif #endif
} }
...@@ -1345,12 +1346,8 @@ class DictionaryElementsAccessor ...@@ -1345,12 +1346,8 @@ class DictionaryElementsAccessor
dict->ElementsRemoved(removed_entries); dict->ElementsRemoved(removed_entries);
} }
if (length <= Smi::kMaxValue) { Handle<Object> length_obj = isolate->factory()->NewNumberFromUint(length);
array->set_length(Smi::FromInt(length)); array->set_length(*length_obj);
} else {
Handle<Object> length_obj = isolate->factory()->NewNumberFromUint(length);
array->set_length(*length_obj);
}
} }
static void DeleteCommon(Handle<JSObject> obj, uint32_t key, static void DeleteCommon(Handle<JSObject> obj, uint32_t key,
......
...@@ -2913,6 +2913,7 @@ bool SeededNumberDictionary::requires_slow_elements() { ...@@ -2913,6 +2913,7 @@ bool SeededNumberDictionary::requires_slow_elements() {
(Smi::cast(max_index_object)->value() & kRequiresSlowElementsMask); (Smi::cast(max_index_object)->value() & kRequiresSlowElementsMask);
} }
uint32_t SeededNumberDictionary::max_number_key() { uint32_t SeededNumberDictionary::max_number_key() {
DCHECK(!requires_slow_elements()); DCHECK(!requires_slow_elements());
Object* max_index_object = get(kMaxNumberKeyIndex); Object* max_index_object = get(kMaxNumberKeyIndex);
...@@ -2921,6 +2922,7 @@ uint32_t SeededNumberDictionary::max_number_key() { ...@@ -2921,6 +2922,7 @@ uint32_t SeededNumberDictionary::max_number_key() {
return value >> kRequiresSlowElementsTagSize; return value >> kRequiresSlowElementsTagSize;
} }
void SeededNumberDictionary::set_requires_slow_elements() { void SeededNumberDictionary::set_requires_slow_elements() {
set(kMaxNumberKeyIndex, Smi::FromInt(kRequiresSlowElementsMask)); set(kMaxNumberKeyIndex, Smi::FromInt(kRequiresSlowElementsMask));
} }
......
This diff is collapsed.
...@@ -2015,14 +2015,11 @@ class JSObject: public JSReceiver { ...@@ -2015,14 +2015,11 @@ class JSObject: public JSReceiver {
// an access at key? // an access at key?
bool WouldConvertToSlowElements(uint32_t index); bool WouldConvertToSlowElements(uint32_t index);
inline bool WouldConvertToSlowElements(Handle<Object> key); inline bool WouldConvertToSlowElements(Handle<Object> key);
// Do we want to keep the elements in fast case when increasing the // Do we want to keep fast elements when adding an element at |index|?
// capacity? // Returns |new_capacity| indicating to which capacity the object should be
bool ShouldConvertToSlowElements(int new_capacity); // increased.
// Returns true if the backing storage for the slow-case elements of bool ShouldConvertToSlowElements(uint32_t capacity, uint32_t index,
// this object takes up nearly as much space as a fast-case backing uint32_t* new_capacity);
// storage would. In that case the JSObject should have fast
// elements.
bool ShouldConvertToFastElements();
ElementsKind BestFittingFastElementsKind(); ElementsKind BestFittingFastElementsKind();
// Computes the new capacity when expanding the elements of a JSObject. // Computes the new capacity when expanding the elements of a JSObject.
...@@ -10140,10 +10137,6 @@ class JSArray: public JSObject { ...@@ -10140,10 +10137,6 @@ class JSArray: public JSObject {
// is set to a smi. This matches the set function on FixedArray. // is set to a smi. This matches the set function on FixedArray.
inline void set_length(Smi* length); inline void set_length(Smi* length);
static void JSArrayUpdateLengthFromIndex(Handle<JSArray> array,
uint32_t index,
Handle<Object> value);
static bool HasReadOnlyLength(Handle<JSArray> array); static bool HasReadOnlyLength(Handle<JSArray> array);
static bool WouldChangeReadOnlyLength(Handle<JSArray> array, uint32_t index); static bool WouldChangeReadOnlyLength(Handle<JSArray> array, uint32_t index);
static MaybeHandle<Object> ReadOnlyLengthError(Handle<JSArray> array); static MaybeHandle<Object> ReadOnlyLengthError(Handle<JSArray> array);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment