Commit 55f90350 authored by cbruni's avatar cbruni Committed by Commit bot

[runtime] enable fast key accumulator by default

BUG=

Review-Url: https://codereview.chromium.org/2162393002
Cr-Commit-Position: refs/heads/master@{#37932}
parent 6b5949a8
......@@ -1025,19 +1025,22 @@ class ElementsAccessorBase : public ElementsAccessor {
Isolate* isolate = object->GetIsolate();
uint32_t nof_property_keys = keys->length();
uint32_t initial_list_length =
Subclass::GetCapacityImpl(*object, *backing_store);
Subclass::GetMaxNumberOfEntries(*object, *backing_store);
initial_list_length += nof_property_keys;
bool needs_sorting =
IsDictionaryElementsKind(kind()) || IsSloppyArgumentsElements(kind());
// Collect the element indices into a new list.
uint32_t nof_indices = 0;
Handle<FixedArray> combined_keys =
isolate->factory()->NewFixedArray(initial_list_length);
combined_keys = Subclass::DirectCollectElementIndicesImpl(
isolate, object, backing_store, convert, filter, combined_keys,
&nof_indices);
isolate, object, backing_store,
needs_sorting ? GetKeysConversion::kKeepNumbers : convert, filter,
combined_keys, &nof_indices);
// Sort the indices list if necessary.
if (IsDictionaryElementsKind(kind()) || IsSloppyArgumentsElements(kind())) {
if (needs_sorting) {
SortIndices(combined_keys, nof_indices, SKIP_WRITE_BARRIER);
uint32_t array_length = 0;
// Indices from dictionary elements should only be converted after
......@@ -1064,7 +1067,9 @@ class ElementsAccessorBase : public ElementsAccessor {
CopyObjectToObjectElements(*keys, FAST_ELEMENTS, 0, *combined_keys,
FAST_ELEMENTS, nof_indices, nof_property_keys);
if (IsHoleyElementsKind(kind())) {
// For holey elements and arguments we might have to shrink the collected
// keys since the estimates might be off.
if (IsHoleyElementsKind(kind()) || IsSloppyArgumentsElements(kind())) {
// Shrink combined_keys to the final size.
int final_size = nof_indices + nof_property_keys;
DCHECK_LE(final_size, combined_keys->length());
......@@ -2353,6 +2358,14 @@ class SloppyArgumentsElementsAccessor
ArgumentsAccessor::GetCapacityImpl(holder, arguments);
}
static uint32_t GetMaxNumberOfEntries(JSObject* holder,
FixedArrayBase* backing_store) {
FixedArray* parameter_map = FixedArray::cast(backing_store);
FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1));
return parameter_map->length() - 2 +
ArgumentsAccessor::GetMaxNumberOfEntries(holder, arguments);
}
static void AddElementsToKeyAccumulatorImpl(Handle<JSObject> receiver,
KeyAccumulator* accumulator,
AddKeyConversion convert) {
......
......@@ -31,15 +31,15 @@ static bool ContainsOnlyValidKeys(Handle<FixedArray> array) {
}
} // namespace
// static
MaybeHandle<FixedArray> KeyAccumulator::GetKeys(
Handle<JSReceiver> object, KeyCollectionMode mode, PropertyFilter filter,
GetKeysConversion keys_conversion, bool filter_proxy_keys, bool is_for_in) {
Isolate* isolate = object->GetIsolate();
KeyAccumulator accumulator(isolate, mode, filter);
FastKeyAccumulator accumulator(isolate, object, mode, filter);
accumulator.set_filter_proxy_keys(filter_proxy_keys);
accumulator.set_is_for_in(is_for_in);
MAYBE_RETURN(accumulator.CollectKeys(object, object),
MaybeHandle<FixedArray>());
return accumulator.GetKeys(keys_conversion);
}
......
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