Revision: 10656
Author:   [email protected]
Date:     Thu Feb  9 01:55:14 2012
Log:      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
http://code.google.com/p/v8/source/detail?r=10656

Modified:
 /branches/bleeding_edge/src/objects.cc

=======================================
--- /branches/bleeding_edge/src/objects.cc      Thu Feb  9 00:58:19 2012
+++ /branches/bleeding_edge/src/objects.cc      Thu Feb  9 01:55:14 2012
@@ -5728,6 +5728,11 @@
     set(kEnumerationIndexIndex, bridge_storage);
   }
 }
+
+
+static bool InsertionPointFound(String* key1, String* key2) {
+  return key1->Hash() > key2->Hash() || key1 == key2;
+}


 MaybeObject* DescriptorArray::CopyInsert(Descriptor* descriptor,
@@ -5802,28 +5807,24 @@

   // 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;
-    }
-    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);
-  }
+  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 (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

Reply via email to