Chromium Code Reviews| Index: vm/object.h |
| =================================================================== |
| --- vm/object.h (revision 4983) |
| +++ vm/object.h (working copy) |
| @@ -3299,6 +3299,11 @@ |
| // Returns the preallocated empty array, used to initialize array fields. |
| static RawArray* Empty(); |
| + // Make an Array object from a growable Array by truncating it to the |
|
cshapiro
2012/03/06 00:56:31
This is a bit confusing to me. A growable array c
siva
2012/03/06 23:32:33
Yes it returns the underlying array but truncates
cshapiro
2012/03/07 00:12:53
This is much better, however it does not mention t
siva
2012/03/08 00:51:56
Done.
|
| + // actual size if needed, the truncated part is marked as an Array object |
| + // or a regular Object so that it can be traversed during garbage collection. |
| + static RawArray* MakeArray(const GrowableObjectArray& growable_array); |
| + |
| protected: |
| static RawArray* New(const Class& cls, |
| intptr_t len, |
| @@ -3335,6 +3340,78 @@ |
| }; |
| +class GrowableObjectArray : public Instance { |
|
cshapiro
2012/03/06 00:56:31
Class documentation? (I am not so good about this
siva
2012/03/06 23:32:33
I was trying to stick to the comment style used in
|
| + public: |
| + intptr_t Capacity() const { |
| + ASSERT(!IsNull()); |
| + return raw_ptr()->capacity_; |
| + } |
| + intptr_t Length() const { |
| + ASSERT(!IsNull()); |
| + return raw_ptr()->length_; |
| + } |
| + |
| + RawObject* At(intptr_t index) const { |
| + ASSERT(!IsNull()); |
| + ASSERT(index < Length()); |
| + const Array& contents = Array::Handle(data()); |
|
hausner
2012/03/06 00:30:47
Is there no way around accessing a growable array
siva
2012/03/06 23:32:33
I have modified this code to avoid creation of the
hausner
2012/03/06 23:53:58
Nice, thank you.
On 2012/03/06 23:32:33, asiva wr
|
| + return contents.At(index); |
| + } |
| + void SetAt(intptr_t index, const Object& value) const { |
| + ASSERT(!IsNull()); |
| + ASSERT(index < Length()); |
| + const Array& contents = Array::Handle(data()); |
| + contents.SetAt(index, value); |
| + } |
| + |
| + void Add(const Object& value, Heap::Space space = Heap::kNew) const; |
| + RawObject* RemoveLast() const; |
| + |
| + virtual RawAbstractTypeArguments* GetTypeArguments() const { |
| + const Array& contents = Array::Handle(data()); |
| + return contents.GetTypeArguments(); |
| + } |
| + virtual void SetTypeArguments(const AbstractTypeArguments& value) const { |
| + const Array& contents = Array::Handle(data()); |
| + contents.SetTypeArguments(value); |
| + } |
| + |
| + virtual bool Equals(const Instance& other) const; |
| + |
| + static intptr_t capacity_offset() { |
| + return OFFSET_OF(RawGrowableObjectArray, capacity_); |
| + } |
| + static intptr_t length_offset() { |
| + return OFFSET_OF(RawGrowableObjectArray, length_); |
| + } |
| + static intptr_t data_offset() { |
| + return OFFSET_OF(RawGrowableObjectArray, data_); |
| + } |
| + |
| + static intptr_t InstanceSize() { |
| + return RoundedAllocationSize(sizeof(RawGrowableObjectArray)); |
| + } |
| + |
| + static RawGrowableObjectArray* New(Heap::Space space = Heap::kNew) { |
| + return New(kDefaultInitialCapacity, space); |
| + } |
| + static RawGrowableObjectArray* New(intptr_t capacity, |
| + Heap::Space space = Heap::kNew); |
| + |
| + private: |
| + RawArray* data() const { return raw_ptr()->data_; } |
| + void set_length(intptr_t value) const { raw_ptr()->length_ = value; } |
| + void set_capacity(intptr_t value) const { raw_ptr()->capacity_ = value; } |
| + void set_data(const Array& value) const { raw_ptr()->data_ = value.raw(); } |
| + |
| + static const int kDefaultInitialCapacity = 4; |
| + |
| + HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); |
| + friend class Class; |
| + friend class Array; |
| +}; |
| + |
| + |
| class ByteArray : public Instance { |
| public: |
| virtual intptr_t Length() const; |