Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Unified Diff: src/objects-inl.h

Issue 10824042: Use linear backing store for hidden properties to save memory. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.cc ('k') | src/v8globals.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 8b22755c8230211278b9874ce97415cdb4fcf9f2..92b312456d80a4d6bae5a2e81efb395952639175 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -520,6 +520,11 @@ TYPE_CHECKER(FixedArray, FIXED_ARRAY_TYPE)
TYPE_CHECKER(FixedDoubleArray, FIXED_DOUBLE_ARRAY_TYPE)
+bool Object::IsHiddenPropertiesArray() {
+ return IsFixedArray();
+}
+
+
bool Object::IsDescriptorArray() {
return IsFixedArray();
}
@@ -1879,6 +1884,72 @@ Object** FixedArray::data_start() {
}
+MaybeObject* HiddenPropertiesArray::Allocate() {
+ static const int initial_size = 2;
+ ASSERT(IS_POWER_OF_TWO(initial_size));
+ return Isolate::Current()->heap()->AllocateFixedArrayWithHoles(initial_size);
+}
+
+
+MaybeObject* HiddenPropertiesArray::Set(String* key, Object* value) {
+ for (int i = 0; i < length(); i += 2) {
+ if (is_the_hole(i) || String::cast(get(i))->Equals(key)) {
+ set(i, key);
+ set(i + 1, value);
+ return this;
+ }
+ }
+ // Need to extend the backing store.
+ int old_size = length();
+ int new_size = old_size << 1;
+ ASSERT(IS_POWER_OF_TWO(new_size));
+ FixedArray* new_array;
+ { MaybeObject* maybe_obj = GetHeap()->AllocateFixedArrayWithHoles(new_size);
+ if (!maybe_obj->To<FixedArray>(&new_array)) return maybe_obj;
+ }
+ CopyTo(0, new_array, 0, old_size);
+ new_array->set(old_size, key);
+ new_array->set(old_size + 1, value);
+ return new_array;
+}
+
+
+void HiddenPropertiesArray::Delete(String* key) {
+ // Linear search to find the key and delete the entry.
+ for (int i = 0; i < length(); i += 2) {
+ if (is_the_hole(i)) {
+ if (is_the_hole(i + 1)) {
+ // Both key and value are holes. This is the end of the list.
+ return;
+ }
+ } else if (String::cast(get(i))->Equals(key)) {
+ // Set the value field to undefined (not the hole) to signal that the
+ // list may not end here.
+ set_the_hole(i);
+ set_undefined(i + 1);
+ return;
+ }
+ }
+}
+
+
+Object* HiddenPropertiesArray::Get(String* key) {
+ // Linear search to find the key and return the value.
+ for (int i = 0; i < length(); i += 2) {
+ if (is_the_hole(i)) {
+ if (is_the_hole(i + 1)) {
+ // Both key and value are holes. This is the end of the list.
+ break;
+ }
+ } else if (String::cast(get(i))->Equals(key)) {
+ return get(i + 1);
+ }
+ }
+ // Not found, return undefined.
+ return GetHeap()->undefined_value();
+}
+
+
bool DescriptorArray::IsEmpty() {
ASSERT(length() >= kFirstIndex ||
this == HEAP->empty_descriptor_array());
@@ -2219,6 +2290,7 @@ void SeededNumberDictionary::set_requires_slow_elements() {
CAST_ACCESSOR(FixedArray)
CAST_ACCESSOR(FixedDoubleArray)
+CAST_ACCESSOR(HiddenPropertiesArray)
CAST_ACCESSOR(DescriptorArray)
CAST_ACCESSOR(DeoptimizationInputData)
CAST_ACCESSOR(DeoptimizationOutputData)
« no previous file with comments | « src/objects.cc ('k') | src/v8globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698