Reviewers: Jakob,

Description:
Consolidated property counting methods a bit.


Please review this at http://codereview.chromium.org/9317119/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/handles.cc
  M src/objects.h
  M src/objects.cc
  M src/runtime.cc


Index: src/handles.cc
diff --git a/src/handles.cc b/src/handles.cc
index 34eaddbbd71e7395c360430a2f237df2bd484145..943a1c0b6ac833e1a0a5e614857e8bfd45a2e7ed 100644
--- a/src/handles.cc
+++ b/src/handles.cc
@@ -711,7 +711,7 @@ Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
                                 isolate);
     }
     isolate->counters()->enum_cache_misses()->Increment();
-    int num_enum = object->NumberOfEnumProperties();
+    int num_enum = object->NumberOfLocalProperties(DONT_ENUM);
Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum);
     Handle<DescriptorArray> descs =
@@ -735,7 +735,7 @@ Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
     ASSERT(storage->length() == index);
     return storage;
   } else {
-    int num_enum = object->NumberOfEnumProperties();
+    int num_enum = object->NumberOfLocalProperties(DONT_ENUM);
Handle<FixedArray> storage = isolate->factory()->NewFixedArray(num_enum); Handle<FixedArray> sort_array = isolate->factory()->NewFixedArray(num_enum);
     object->property_dictionary()->CopyEnumKeysTo(*storage, *sort_array);
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 692fa87e6b733f9d72c0fdad58ec0797abe68527..8e55700f536f8294e0238dc4246f60717a206406 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -4247,11 +4247,14 @@ bool JSReceiver::IsSimpleEnum() {
 }


-int Map::NumberOfDescribedProperties() {
+int Map::NumberOfDescribedProperties(PropertyAttributes filter) {
   int result = 0;
   DescriptorArray* descs = instance_descriptors();
   for (int i = 0; i < descs->number_of_descriptors(); i++) {
-    if (descs->IsProperty(i)) result++;
+      PropertyDetails details(descs->GetDetails(i));
+      if (descs->IsProperty(i) && (details.attributes() & filter) == 0) {
+        result++;
+      }
   }
   return result;
 }
@@ -10355,24 +10358,9 @@ bool JSObject::HasRealNamedCallbackProperty(String* key) {


 int JSObject::NumberOfLocalProperties(PropertyAttributes filter) {
-  if (HasFastProperties()) {
-    DescriptorArray* descs = map()->instance_descriptors();
-    int result = 0;
-    for (int i = 0; i < descs->number_of_descriptors(); i++) {
-      PropertyDetails details(descs->GetDetails(i));
-      if (descs->IsProperty(i) && (details.attributes() & filter) == 0) {
-        result++;
-      }
-    }
-    return result;
-  } else {
-    return property_dictionary()->NumberOfElementsFilterAttributes(filter);
-  }
-}
-
-
-int JSObject::NumberOfEnumProperties() {
- return NumberOfLocalProperties(static_cast<PropertyAttributes>(DONT_ENUM));
+  return HasFastProperties() ?
+      map()->NumberOfDescribedProperties(filter) :
+      property_dictionary()->NumberOfElementsFilterAttributes(filter);
 }


@@ -10493,7 +10481,7 @@ void FixedArray::SortPairs(FixedArray* numbers, uint32_t len) { // purpose of this function is to provide reflection information for the object
 // mirrors.
 void JSObject::GetLocalPropertyNames(FixedArray* storage, int index) {
-  ASSERT(storage->length() >= (NumberOfLocalProperties(NONE) - index));
+  ASSERT(storage->length() >= (NumberOfLocalProperties() - index));
   if (HasFastProperties()) {
     DescriptorArray* descs = map()->instance_descriptors();
     for (int i = 0; i < descs->number_of_descriptors(); i++) {
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 6edd6cce9a0b2e7ae0efb8365bead28a050c0e1e..17e66d704ccf86c2b2b3c663b661c40f093dfd84 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -1807,9 +1807,7 @@ class JSObject: public JSReceiver {

// Returns the number of properties on this object filtering out properties
   // with the specified attributes (ignoring interceptors).
-  int NumberOfLocalProperties(PropertyAttributes filter);
-  // Returns the number of enumerable properties (ignoring interceptors).
-  int NumberOfEnumProperties();
+  int NumberOfLocalProperties(PropertyAttributes filter = NONE);
   // Fill in details for properties into storage starting at the specified
   // index.
   void GetLocalPropertyNames(FixedArray* storage, int index);
@@ -4638,8 +4636,9 @@ class Map: public HeapObject {
   // Returns the next free property index (only valid for FAST MODE).
   int NextFreePropertyIndex();

-  // Returns the number of properties described in instance_descriptors.
-  int NumberOfDescribedProperties();
+  // Returns the number of properties described in instance_descriptors
+  // filtering out properties with the specified attributes.
+  int NumberOfDescribedProperties(PropertyAttributes filter = NONE);

   // Casting.
   static inline Map* cast(Object* obj);
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 308ef86805cbb90141c3fd69fc11b48f667a2d51..e46b855b0748886a5dfdcb2d43fcc1f8f7836639 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -165,7 +165,7 @@ MUST_USE_RESULT static MaybeObject* DeepCopyBoilerplate(Isolate* isolate,
     }
   } else {
     { MaybeObject* maybe_result =
-          heap->AllocateFixedArray(copy->NumberOfLocalProperties(NONE));
+          heap->AllocateFixedArray(copy->NumberOfLocalProperties());
       if (!maybe_result->ToObject(&result)) return maybe_result;
     }
     FixedArray* names = FixedArray::cast(result);
@@ -5010,7 +5010,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetLocalPropertyNames) {
       return *isolate->factory()->NewJSArray(0);
     }
     int n;
- n = jsproto->NumberOfLocalProperties(static_cast<PropertyAttributes>(NONE));
+    n = jsproto->NumberOfLocalProperties();
     local_property_count[i] = n;
     total_property_count += n;
     if (i < length - 1) {


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to