| Index: src/objects.cc
|
| diff --git a/src/objects.cc b/src/objects.cc
|
| index 46539311de9625d9c7ffccc54bd476ab5510a47b..a72585d696948c827a1659fb0d0c201003b9ac11 100644
|
| --- a/src/objects.cc
|
| +++ b/src/objects.cc
|
| @@ -9501,37 +9501,55 @@ void Map::ZapPrototypeTransitions() {
|
| }
|
|
|
|
|
| -Handle<DependentCodes> DependentCodes::Append(Handle<DependentCodes> codes,
|
| +Handle<DependentCodes> DependentCodes::Insert(Handle<DependentCodes> codes,
|
| + DependencyGroup group,
|
| Handle<Code> value) {
|
| - int append_index = codes->number_of_codes();
|
| - if (append_index > 0 && codes->code_at(append_index - 1) == *value) {
|
| + GroupStartIndexes starts;
|
| + codes->ComputeGroupStartIndexes(starts);
|
| + int start = starts[group];
|
| + int end = starts[group + 1];
|
| + int number_of_codes = starts[kGroupCount];
|
| + if (start < end && codes->code_at(end - 1) == *value) {
|
| // Do not append the code if it is already in the array.
|
| // It is sufficient to just check only the last element because
|
| // we process embedded maps of an optimized code in one batch.
|
| return codes;
|
| }
|
| - if (codes->length() < kCodesIndex + append_index + 1) {
|
| + if (codes->length() < kCodesStartIndex + number_of_codes + 1) {
|
| Factory* factory = codes->GetIsolate()->factory();
|
| - int capacity = kCodesIndex + append_index + 1;
|
| + int capacity = kCodesStartIndex + number_of_codes + 1;
|
| if (capacity > 5) capacity = capacity * 5 / 4;
|
| Handle<DependentCodes> new_codes = Handle<DependentCodes>::cast(
|
| factory->CopySizeFixedArray(codes, capacity));
|
| // The number of codes can change after GC.
|
| - append_index = codes->number_of_codes();
|
| - for (int i = 0; i < append_index; i++) {
|
| + codes->ComputeGroupStartIndexes(starts);
|
| + start = starts[group];
|
| + end = starts[group + 1];
|
| + number_of_codes = starts[kGroupCount];
|
| + for (int i = 0; i < number_of_codes; i++) {
|
| codes->clear_code_at(i);
|
| }
|
| + // If the old fixed array was empty, we need to reset counters of the
|
| + // new array.
|
| + if (number_of_codes == 0) {
|
| + for (int g = 0; g < kGroupCount; g++) {
|
| + new_codes->set_number_of_codes(static_cast<DependencyGroup>(g), 0);
|
| + }
|
| + }
|
| codes = new_codes;
|
| }
|
| - codes->set_code_at(append_index, *value);
|
| - codes->set_number_of_codes(append_index + 1);
|
| + codes->ExtendGroup(group);
|
| + codes->set_code_at(end, *value);
|
| + codes->set_number_of_codes(group, end + 1 - start);
|
| return codes;
|
| }
|
|
|
|
|
| -bool DependentCodes::Contains(Code* code) {
|
| - int limit = number_of_codes();
|
| - for (int i = 0; i < limit; i++) {
|
| +bool DependentCodes::Contains(DependencyGroup group, Code* code) {
|
| + GroupStartIndexes starts;
|
| + ComputeGroupStartIndexes(starts);
|
| + int number_of_codes = starts[kGroupCount];
|
| + for (int i = 0; i < number_of_codes; i++) {
|
| if (code_at(i) == code) return true;
|
| }
|
| return false;
|
|
|