Chromium Code Reviews| Index: vm/object.cc |
| =================================================================== |
| --- vm/object.cc (revision 6293) |
| +++ 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()); |
| @@ -8568,7 +8574,7 @@ |
| ASSERT(!IsNull()); |
| Array& contents = Array::Handle(data()); |
| if (Length() == Capacity()) { |
| - intptr_t new_capacity = Capacity() * 2; |
| + intptr_t new_capacity = (Capacity() == 0) ? 4 : Capacity() * 2; |
|
srdjan
2012/04/06 21:19:51
Capacity * 2 may be to-harsh. Adding one element t
siva
2012/04/09 20:57:24
I have opened a Bug to track this and figure out h
|
| if (new_capacity <= Capacity()) { |
| // Use the preallocated out of memory exception to avoid calling |
| // into dart code or allocating any code. |
| @@ -8577,8 +8583,7 @@ |
| Exceptions::Throw(exception); |
| UNREACHABLE(); |
| } |
| - StorePointer(&(raw_ptr()->data_), |
| - Array::Grow(contents, new_capacity, space)); |
| + Grow(new_capacity, space); |
| contents = data(); |
| } |
| ASSERT(Length() < Capacity()); |
| @@ -8588,6 +8593,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); |
| @@ -8640,9 +8653,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, |
| @@ -8651,7 +8670,7 @@ |
| NoGCScope no_gc; |
| result ^= raw; |
| result.SetLength(0); |
| - result.SetData(data); |
| + result.SetData(array); |
| } |
| return result.raw(); |
| } |