Commit 45e3c56d authored by Franziska Hinkelmann's avatar Franziska Hinkelmann Committed by Commit Bot

[cleanup] Add Elements() to ArrayList.

ArrayList is a FixedArray where kFirstIndex is > 0. The
Elements() methods returns a copy of the elements starting at
kFirstIndex, i.e., without the length that is stored in the first
slot.

Drive-by fix: Rename some variables.

BUG=

Change-Id: Ia1de73c4780a179301007f2ab9080fd08e8ea99d
Reviewed-on: https://chromium-review.googlesource.com/466186Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Commit-Queue: Franziska Hinkelmann <franzih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44365}
parent 28a3e34b
......@@ -926,19 +926,19 @@ void CollectTypeProfileNexus::Collect(Handle<String> type, int position) {
UnseededNumberDictionary::cast(feedback), isolate);
}
Handle<ArrayList> types_for_position;
Handle<ArrayList> position_specific_types;
if (types->Has(position)) {
int entry = types->FindEntry(position);
DCHECK(types->ValueAt(entry)->IsArrayList());
types_for_position =
position_specific_types =
Handle<ArrayList>(ArrayList::cast(types->ValueAt(entry)));
} else {
types_for_position = ArrayList::New(isolate, 1);
position_specific_types = ArrayList::New(isolate, 1);
}
types = UnseededNumberDictionary::Set(
types, position, ArrayList::Add(types_for_position, type));
types, position, ArrayList::Add(position_specific_types, type));
SetFeedback(*types);
}
......@@ -957,19 +957,14 @@ Handle<JSObject> ConvertToJSObject(Isolate* isolate,
if (key->IsSmi()) {
int value_index = index + UnseededNumberDictionary::kEntryValueIndex;
Handle<ArrayList> orig = Handle<ArrayList>(
Handle<ArrayList> position_specific_types = Handle<ArrayList>(
ArrayList::cast(feedback->get(value_index)), isolate);
// Delete the first entry, i.e., the length.
Handle<FixedArray> storage =
isolate->factory()->NewFixedArray(orig->Length());
orig->CopyTo(1, *storage, 0, orig->Length());
int pos = Smi::cast(key)->value();
JSObject::AddDataElement(
type_profile, pos,
isolate->factory()->NewJSArrayWithElements(storage),
PropertyAttributes::NONE)
int position = Smi::cast(key)->value();
JSObject::AddDataElement(type_profile, position,
isolate->factory()->NewJSArrayWithElements(
position_specific_types->Elements()),
PropertyAttributes::NONE)
.ToHandleChecked();
}
}
......
......@@ -10039,6 +10039,13 @@ Handle<ArrayList> ArrayList::New(Isolate* isolate, int size) {
return result;
}
Handle<FixedArray> ArrayList::Elements() {
Handle<FixedArray> result = GetIsolate()->factory()->NewFixedArray(Length());
// Do not copy the first entry, i.e., the length.
CopyTo(kFirstIndex, *result, 0, Length());
return result;
}
bool ArrayList::IsFull() {
int capacity = length();
return kFirstIndex + Length() == capacity;
......
......@@ -2966,6 +2966,9 @@ class ArrayList : public FixedArray {
inline void Set(int index, Object* obj,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline void Clear(int index, Object* undefined);
// Return a copy of the list without the first entry (contains the Length).
Handle<FixedArray> Elements();
bool IsFull();
DECLARE_CAST(ArrayList)
......
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