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

Unified Diff: vm/object.h

Issue 9594028: Add a first class GrowableObjectArray type in the VM and use it internally in the VM at all spots w… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 10 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.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;

Powered by Google App Engine
This is Rietveld 408576698