[cleanup] Clean kFullTransitionArray path in TransitionsAccessor::Insert
There is a case where a TransitionArray shrinks during insertion. If that's the case, we need to compute the index to insert again. However, we can use the knowledge that already didn't appear in the array, and after shrinking it shouldn't appear. Change-Id: I3a742c5d37659064f143db1c4f345b0df35d0d42 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2238029 Reviewed-by: Georg Neis <neis@chromium.org> Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org> Cr-Commit-Position: refs/heads/master@{#68462}
This commit is contained in:
parent
6a546bd967
commit
0da6b2cbfe
@ -105,7 +105,6 @@ void TransitionsAccessor::Insert(Handle<Name> name, Handle<Map> target,
|
||||
DisallowHeapAllocation no_gc;
|
||||
TransitionArray array = transitions();
|
||||
number_of_transitions = array.number_of_transitions();
|
||||
new_nof = number_of_transitions;
|
||||
|
||||
int index = is_special_transition
|
||||
? array.SearchSpecial(Symbol::cast(*name), &insertion_index)
|
||||
@ -117,19 +116,20 @@ void TransitionsAccessor::Insert(Handle<Name> name, Handle<Map> target,
|
||||
return;
|
||||
}
|
||||
|
||||
++new_nof;
|
||||
new_nof = number_of_transitions + 1;
|
||||
CHECK_LE(new_nof, kMaxNumberOfTransitions);
|
||||
DCHECK(insertion_index >= 0 && insertion_index <= number_of_transitions);
|
||||
DCHECK_GE(insertion_index, 0);
|
||||
DCHECK_LE(insertion_index, number_of_transitions);
|
||||
|
||||
// If there is enough capacity, insert new entry into the existing array.
|
||||
if (new_nof <= array.Capacity()) {
|
||||
array.SetNumberOfTransitions(new_nof);
|
||||
for (index = number_of_transitions; index > insertion_index; --index) {
|
||||
array.SetKey(index, array.GetKey(index - 1));
|
||||
array.SetRawTarget(index, array.GetRawTarget(index - 1));
|
||||
for (int i = number_of_transitions; i > insertion_index; --i) {
|
||||
array.SetKey(i, array.GetKey(i - 1));
|
||||
array.SetRawTarget(i, array.GetRawTarget(i - 1));
|
||||
}
|
||||
array.SetKey(index, *name);
|
||||
array.SetRawTarget(index, HeapObjectReference::Weak(*target));
|
||||
array.SetKey(insertion_index, *name);
|
||||
array.SetRawTarget(insertion_index, HeapObjectReference::Weak(*target));
|
||||
SLOW_DCHECK(array.IsSortedNoDuplicates());
|
||||
return;
|
||||
}
|
||||
@ -147,23 +147,19 @@ void TransitionsAccessor::Insert(Handle<Name> name, Handle<Map> target,
|
||||
DisallowHeapAllocation no_gc;
|
||||
TransitionArray array = transitions();
|
||||
if (array.number_of_transitions() != number_of_transitions) {
|
||||
DCHECK(array.number_of_transitions() < number_of_transitions);
|
||||
DCHECK_LT(array.number_of_transitions(), number_of_transitions);
|
||||
|
||||
number_of_transitions = array.number_of_transitions();
|
||||
new_nof = number_of_transitions;
|
||||
|
||||
insertion_index = kNotFound;
|
||||
int index = is_special_transition
|
||||
? array.SearchSpecial(Symbol::cast(*name), &insertion_index)
|
||||
: array.Search(details.kind(), *name, details.attributes(),
|
||||
&insertion_index);
|
||||
if (index == kNotFound) {
|
||||
++new_nof;
|
||||
} else {
|
||||
insertion_index = index;
|
||||
}
|
||||
DCHECK(insertion_index >= 0 && insertion_index <= number_of_transitions);
|
||||
CHECK_EQ(index, kNotFound);
|
||||
USE(index);
|
||||
DCHECK_GE(insertion_index, 0);
|
||||
DCHECK_LE(insertion_index, number_of_transitions);
|
||||
|
||||
number_of_transitions = array.number_of_transitions();
|
||||
new_nof = number_of_transitions + 1;
|
||||
result->SetNumberOfTransitions(new_nof);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user