Cleaned up DescriptorArray::CopyInsert a bit.
The point of this refactoring is to remove some copy 'n' paste from the code, preparing some upcoming changes related to CopyFrom and CALLBACKS with transitions. The index fiddling is tricky enough to warrant a separate refacoring-only CL... Review URL: https://chromiumcodereview.appspot.com/9371013 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10656 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
19a62a22fc
commit
fdf31d1bff
@ -5730,6 +5730,11 @@ void DescriptorArray::SetEnumCache(FixedArray* bridge_storage,
|
||||
}
|
||||
|
||||
|
||||
static bool InsertionPointFound(String* key1, String* key2) {
|
||||
return key1->Hash() > key2->Hash() || key1 == key2;
|
||||
}
|
||||
|
||||
|
||||
MaybeObject* DescriptorArray::CopyInsert(Descriptor* descriptor,
|
||||
TransitionFlag transition_flag) {
|
||||
// Transitions are only kept when inserting another transition.
|
||||
@ -5802,28 +5807,24 @@ MaybeObject* DescriptorArray::CopyInsert(Descriptor* descriptor,
|
||||
|
||||
// Copy the descriptors, filtering out transitions and null descriptors,
|
||||
// and inserting or replacing a descriptor.
|
||||
uint32_t descriptor_hash = descriptor->GetKey()->Hash();
|
||||
int from_index = 0;
|
||||
int to_index = 0;
|
||||
|
||||
for (; from_index < number_of_descriptors(); from_index++) {
|
||||
String* key = GetKey(from_index);
|
||||
if (key->Hash() > descriptor_hash || key == descriptor->GetKey()) {
|
||||
break;
|
||||
int insertion_index = -1;
|
||||
int from_index = 0;
|
||||
while (from_index < number_of_descriptors()) {
|
||||
if (insertion_index < 0 &&
|
||||
InsertionPointFound(GetKey(from_index), descriptor->GetKey())) {
|
||||
insertion_index = to_index++;
|
||||
if (replacing) from_index++;
|
||||
} else {
|
||||
if (!(IsNullDescriptor(from_index) ||
|
||||
(remove_transitions && IsTransitionOnly(from_index)))) {
|
||||
new_descriptors->CopyFrom(to_index++, this, from_index, witness);
|
||||
}
|
||||
from_index++;
|
||||
}
|
||||
if (IsNullDescriptor(from_index)) continue;
|
||||
if (remove_transitions && IsTransitionOnly(from_index)) continue;
|
||||
new_descriptors->CopyFrom(to_index++, this, from_index, witness);
|
||||
}
|
||||
|
||||
new_descriptors->Set(to_index++, descriptor, witness);
|
||||
if (replacing) from_index++;
|
||||
|
||||
for (; from_index < number_of_descriptors(); from_index++) {
|
||||
if (IsNullDescriptor(from_index)) continue;
|
||||
if (remove_transitions && IsTransitionOnly(from_index)) continue;
|
||||
new_descriptors->CopyFrom(to_index++, this, from_index, witness);
|
||||
}
|
||||
if (insertion_index < 0) insertion_index = to_index++;
|
||||
new_descriptors->Set(insertion_index, descriptor, witness);
|
||||
|
||||
ASSERT(to_index == new_descriptors->number_of_descriptors());
|
||||
SLOW_ASSERT(new_descriptors->IsSortedNoDuplicates());
|
||||
|
Loading…
Reference in New Issue
Block a user