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

Unified Diff: vm/object.cc

Issue 10012042: Wire GrowableArray to use the internal VM object. (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
Index: vm/object.cc
===================================================================
--- vm/object.cc (revision 6332)
+++ vm/object.cc (working copy)
@@ -457,6 +457,8 @@
// class is setup as one of its field is an array object).
cls = Class::New<GrowableObjectArray>();
object_store->set_growable_object_array_class(cls);
+ cls.set_type_arguments_instance_field_offset(
+ GrowableObjectArray::type_arguments_offset());
// Setup the symbol table used within the String class.
const int kInitialSymbolTableSize = 16;
@@ -521,6 +523,10 @@
RegisterClass(cls, "ObjectArray", impl_script, core_impl_lib);
pending_classes.Add(cls, Heap::kOld);
+ cls = object_store->growable_object_array_class(); // Was allocated above.
+ RegisterClass(cls, "GrowableObjectArray", impl_script, core_impl_lib);
+ pending_classes.Add(cls, Heap::kOld);
+
cls = Class::New<ImmutableArray>();
object_store->set_immutable_array_class(cls);
cls.set_type_arguments_instance_field_offset(Array::type_arguments_offset());
@@ -8572,7 +8578,8 @@
ASSERT(!IsNull());
Array& contents = Array::Handle(data());
if (Length() == Capacity()) {
- intptr_t new_capacity = Capacity() * 2;
+ // TODO(Issue 2500): Need a better growth strategy.
+ intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2;
if (new_capacity <= Capacity()) {
// Use the preallocated out of memory exception to avoid calling
// into dart code or allocating any code.
@@ -8581,8 +8588,7 @@
Exceptions::Throw(exception);
UNREACHABLE();
}
- StorePointer(&(raw_ptr()->data_),
- Array::Grow(contents, new_capacity, space));
+ Grow(new_capacity, space);
contents = data();
}
ASSERT(Length() < Capacity());
@@ -8592,6 +8598,14 @@
}
+void GrowableObjectArray::Grow(intptr_t new_capacity, Heap::Space space) const {
+ ASSERT(new_capacity > Capacity());
+ Array& contents = Array::Handle(data());
+ StorePointer(&(raw_ptr()->data_),
+ Array::Grow(contents, new_capacity, space));
+}
+
+
RawObject* GrowableObjectArray::RemoveLast() const {
ASSERT(!IsNull());
ASSERT(Length() > 0);
@@ -8644,9 +8658,15 @@
RawGrowableObjectArray* GrowableObjectArray::New(intptr_t capacity,
Heap::Space space) {
+ const Array& data = Array::Handle(Array::New(capacity, space));
+ return New(data, space);
+}
+
+
+RawGrowableObjectArray* GrowableObjectArray::New(const Array& array,
+ Heap::Space space) {
ObjectStore* object_store = Isolate::Current()->object_store();
Class& cls = Class::Handle(object_store->growable_object_array_class());
- const Array& data = Array::Handle(Array::New(capacity, space));
GrowableObjectArray& result = GrowableObjectArray::Handle();
{
RawObject* raw = Object::Allocate(cls,
@@ -8655,7 +8675,7 @@
NoGCScope no_gc;
result ^= raw;
result.SetLength(0);
- result.SetData(data);
+ result.SetData(array);
}
return result.raw();
}
« lib/growable_array.dart ('K') | « vm/object.h ('k') | vm/opt_code_generator_ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698