Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_OBJECT_H_ | 5 #ifndef VM_OBJECT_H_ |
| 6 #define VM_OBJECT_H_ | 6 #define VM_OBJECT_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "platform/utils.h" | 10 #include "platform/utils.h" |
| (...skipping 3281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3292 // Creates and returns a new array with 'new_length'. Copies all elements from | 3292 // Creates and returns a new array with 'new_length'. Copies all elements from |
| 3293 // 'source' to the new array. 'new_length' must be greater than or equal to | 3293 // 'source' to the new array. 'new_length' must be greater than or equal to |
| 3294 // 'source.Length()'. 'source' can be null. | 3294 // 'source.Length()'. 'source' can be null. |
| 3295 static RawArray* Grow(const Array& source, | 3295 static RawArray* Grow(const Array& source, |
| 3296 int new_length, | 3296 int new_length, |
| 3297 Heap::Space space = Heap::kNew); | 3297 Heap::Space space = Heap::kNew); |
| 3298 | 3298 |
| 3299 // Returns the preallocated empty array, used to initialize array fields. | 3299 // Returns the preallocated empty array, used to initialize array fields. |
| 3300 static RawArray* Empty(); | 3300 static RawArray* Empty(); |
| 3301 | 3301 |
| 3302 // 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.
| |
| 3303 // actual size if needed, the truncated part is marked as an Array object | |
| 3304 // or a regular Object so that it can be traversed during garbage collection. | |
| 3305 static RawArray* MakeArray(const GrowableObjectArray& growable_array); | |
| 3306 | |
| 3302 protected: | 3307 protected: |
| 3303 static RawArray* New(const Class& cls, | 3308 static RawArray* New(const Class& cls, |
| 3304 intptr_t len, | 3309 intptr_t len, |
| 3305 Heap::Space space = Heap::kNew); | 3310 Heap::Space space = Heap::kNew); |
| 3306 | 3311 |
| 3307 private: | 3312 private: |
| 3308 // Make sure that the array size cannot wrap around. | 3313 // Make sure that the array size cannot wrap around. |
| 3309 static const intptr_t kMaxArrayElements = 512 * 1024 * 1024; | 3314 static const intptr_t kMaxArrayElements = 512 * 1024 * 1024; |
| 3310 | 3315 |
| 3311 RawObject** ObjectAddr(intptr_t index) const { | 3316 RawObject** ObjectAddr(intptr_t index) const { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 3328 class ImmutableArray : public Array { | 3333 class ImmutableArray : public Array { |
| 3329 public: | 3334 public: |
| 3330 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew); | 3335 static RawImmutableArray* New(intptr_t len, Heap::Space space = Heap::kNew); |
| 3331 | 3336 |
| 3332 private: | 3337 private: |
| 3333 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); | 3338 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); |
| 3334 friend class Class; | 3339 friend class Class; |
| 3335 }; | 3340 }; |
| 3336 | 3341 |
| 3337 | 3342 |
| 3343 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
| |
| 3344 public: | |
| 3345 intptr_t Capacity() const { | |
| 3346 ASSERT(!IsNull()); | |
| 3347 return raw_ptr()->capacity_; | |
| 3348 } | |
| 3349 intptr_t Length() const { | |
| 3350 ASSERT(!IsNull()); | |
| 3351 return raw_ptr()->length_; | |
| 3352 } | |
| 3353 | |
| 3354 RawObject* At(intptr_t index) const { | |
| 3355 ASSERT(!IsNull()); | |
| 3356 ASSERT(index < Length()); | |
| 3357 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
| |
| 3358 return contents.At(index); | |
| 3359 } | |
| 3360 void SetAt(intptr_t index, const Object& value) const { | |
| 3361 ASSERT(!IsNull()); | |
| 3362 ASSERT(index < Length()); | |
| 3363 const Array& contents = Array::Handle(data()); | |
| 3364 contents.SetAt(index, value); | |
| 3365 } | |
| 3366 | |
| 3367 void Add(const Object& value, Heap::Space space = Heap::kNew) const; | |
| 3368 RawObject* RemoveLast() const; | |
| 3369 | |
| 3370 virtual RawAbstractTypeArguments* GetTypeArguments() const { | |
| 3371 const Array& contents = Array::Handle(data()); | |
| 3372 return contents.GetTypeArguments(); | |
| 3373 } | |
| 3374 virtual void SetTypeArguments(const AbstractTypeArguments& value) const { | |
| 3375 const Array& contents = Array::Handle(data()); | |
| 3376 contents.SetTypeArguments(value); | |
| 3377 } | |
| 3378 | |
| 3379 virtual bool Equals(const Instance& other) const; | |
| 3380 | |
| 3381 static intptr_t capacity_offset() { | |
| 3382 return OFFSET_OF(RawGrowableObjectArray, capacity_); | |
| 3383 } | |
| 3384 static intptr_t length_offset() { | |
| 3385 return OFFSET_OF(RawGrowableObjectArray, length_); | |
| 3386 } | |
| 3387 static intptr_t data_offset() { | |
| 3388 return OFFSET_OF(RawGrowableObjectArray, data_); | |
| 3389 } | |
| 3390 | |
| 3391 static intptr_t InstanceSize() { | |
| 3392 return RoundedAllocationSize(sizeof(RawGrowableObjectArray)); | |
| 3393 } | |
| 3394 | |
| 3395 static RawGrowableObjectArray* New(Heap::Space space = Heap::kNew) { | |
| 3396 return New(kDefaultInitialCapacity, space); | |
| 3397 } | |
| 3398 static RawGrowableObjectArray* New(intptr_t capacity, | |
| 3399 Heap::Space space = Heap::kNew); | |
| 3400 | |
| 3401 private: | |
| 3402 RawArray* data() const { return raw_ptr()->data_; } | |
| 3403 void set_length(intptr_t value) const { raw_ptr()->length_ = value; } | |
| 3404 void set_capacity(intptr_t value) const { raw_ptr()->capacity_ = value; } | |
| 3405 void set_data(const Array& value) const { raw_ptr()->data_ = value.raw(); } | |
| 3406 | |
| 3407 static const int kDefaultInitialCapacity = 4; | |
| 3408 | |
| 3409 HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); | |
| 3410 friend class Class; | |
| 3411 friend class Array; | |
| 3412 }; | |
| 3413 | |
| 3414 | |
| 3338 class ByteArray : public Instance { | 3415 class ByteArray : public Instance { |
| 3339 public: | 3416 public: |
| 3340 virtual intptr_t Length() const; | 3417 virtual intptr_t Length() const; |
| 3341 | 3418 |
| 3342 static void Copy(uint8_t* dst, | 3419 static void Copy(uint8_t* dst, |
| 3343 const ByteArray& src, | 3420 const ByteArray& src, |
| 3344 intptr_t src_offset, | 3421 intptr_t src_offset, |
| 3345 intptr_t length); | 3422 intptr_t length); |
| 3346 | 3423 |
| 3347 static void Copy(const ByteArray& dst, | 3424 static void Copy(const ByteArray& dst, |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3806 } | 3883 } |
| 3807 | 3884 |
| 3808 | 3885 |
| 3809 void Context::SetAt(intptr_t index, const Instance& value) const { | 3886 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 3810 StorePointer(InstanceAddr(index), value.raw()); | 3887 StorePointer(InstanceAddr(index), value.raw()); |
| 3811 } | 3888 } |
| 3812 | 3889 |
| 3813 } // namespace dart | 3890 } // namespace dart |
| 3814 | 3891 |
| 3815 #endif // VM_OBJECT_H_ | 3892 #endif // VM_OBJECT_H_ |
| OLD | NEW |