Keep maps when resetting elements.

R=verwaest@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21838 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 510ea9e5
......@@ -1436,9 +1436,7 @@ class DictionaryElementsAccessor
}
if (new_length == 0) {
// If the length of a slow array is reset to zero, we clear
// the array and flush backing storage. This has the added
// benefit that the array returns to fast mode.
// Flush the backing store.
JSObject::ResetElements(array);
} else {
DisallowHeapAllocation no_gc;
......
......@@ -2738,6 +2738,9 @@ FixedArrayBase* Map::GetInitialElements() {
GetHeap()->EmptyFixedTypedArrayForMap(this);
ASSERT(!GetHeap()->InNewSpace(empty_array));
return empty_array;
} else if (has_dictionary_elements()) {
ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_slow_element_dictionary()));
return GetHeap()->empty_slow_element_dictionary();
} else {
UNREACHABLE();
}
......
......@@ -4793,28 +4793,9 @@ void JSObject::TransformToFastProperties(Handle<JSObject> object,
void JSObject::ResetElements(Handle<JSObject> object) {
if (object->map()->is_observed()) {
// Maintain invariant that observed elements are always in dictionary mode.
Isolate* isolate = object->GetIsolate();
Factory* factory = isolate->factory();
Handle<SeededNumberDictionary> dictionary =
SeededNumberDictionary::New(isolate, 0);
if (object->map() == *factory->sloppy_arguments_elements_map()) {
FixedArray::cast(object->elements())->set(1, *dictionary);
} else {
object->set_elements(*dictionary);
}
return;
}
ElementsKind elements_kind = GetInitialFastElementsKind();
if (!FLAG_smi_only_arrays) {
elements_kind = FastSmiToObjectElementsKind(elements_kind);
}
Handle<Map> map = JSObject::GetElementsTransitionMap(object, elements_kind);
DisallowHeapAllocation no_gc;
Handle<FixedArrayBase> elements(map->GetInitialElements());
JSObject::SetMapAndElements(object, map, elements);
Heap* heap = object->GetIsolate()->heap();
CHECK(object->map() != heap->sloppy_arguments_elements_map());
object->set_elements(object->map()->GetInitialElements());
}
......
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