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

Unified Diff: vm/class_table.cc

Issue 10311006: - Grow the class table as needed instead of preallocating. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 8 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 | « vm/class_table.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/class_table.cc
===================================================================
--- vm/class_table.cc (revision 7234)
+++ vm/class_table.cc (working copy)
@@ -13,13 +13,18 @@
DEFINE_FLAG(bool, print_class_table, false, "Print initial class table.");
ClassTable::ClassTable()
- : top_(kNumPredefinedKinds), capacity_(initial_capacity_), table_(NULL) {
- table_ = reinterpret_cast<RawClass**>(calloc(capacity_,
- sizeof(RawClass*))); // NOLINT
- // Duplicate the class table from the VM isolate.
- if (Dart::vm_isolate() != NULL) {
+ : top_(kNumPredefinedKinds), capacity_(0), table_(NULL) {
+ if (Dart::vm_isolate() == NULL) {
+ capacity_ = initial_capacity_;
+ table_ = reinterpret_cast<RawClass**>(
+ calloc(capacity_, sizeof(RawClass*))); // NOLINT
+ } else {
+ // Duplicate the class table from the VM isolate.
ClassTable* vm_class_table = Dart::vm_isolate()->class_table();
- for (int i = kObject; i < kInstance; i++) {
+ capacity_ = vm_class_table->capacity_;
+ table_ = reinterpret_cast<RawClass**>(
+ calloc(capacity_, sizeof(RawClass*))); // NOLINT
+ for (intptr_t i = kObject; i < kInstance; i++) {
table_[i] = vm_class_table->At(i);
}
table_[kNullClassIndex] = vm_class_table->At(kNullClassIndex);
@@ -40,12 +45,24 @@
ASSERT(index > 0);
ASSERT(index < kNumPredefinedKinds);
ASSERT(table_[index] == 0);
+ ASSERT(index < capacity_);
table_[index] = cls.raw();
} else {
+ if (top_ == capacity_) {
+ // Grow the capacity of the class table.
+ intptr_t new_capacity = capacity_ + capacity_increment_;
+ RawClass** new_table = reinterpret_cast<RawClass**>(
+ realloc(table_, new_capacity * sizeof(RawClass*))); // NOLINT
+ for (intptr_t i = capacity_; i < new_capacity; i++) {
+ new_table[i] = NULL;
+ }
+ capacity_ = new_capacity;
+ table_ = new_table;
+ }
+ ASSERT(top_ < capacity_);
cls.set_index(top_);
table_[top_] = cls.raw();
top_++; // Increment next index.
- ASSERT(top_ < capacity_);
}
}
« no previous file with comments | « vm/class_table.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698