Reviewers: Kevin Millikin,
Description:
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...
Please review this at http://codereview.chromium.org/9371013/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/objects.cc
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
e4f165ae44e5e64051c8ea176e5687b6869ef11b..e21847ab1573a97afbf916965e1f835df39206db
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -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());
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev