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 3232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3243 private: | 3243 private: |
| 3244 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); | 3244 HEAP_OBJECT_IMPLEMENTATION(ImmutableArray, Array); |
| 3245 friend class Class; | 3245 friend class Class; |
| 3246 }; | 3246 }; |
| 3247 | 3247 |
| 3248 | 3248 |
| 3249 class ByteArray : public Instance { | 3249 class ByteArray : public Instance { |
| 3250 public: | 3250 public: |
| 3251 virtual intptr_t Length() const; | 3251 virtual intptr_t Length() const; |
| 3252 | 3252 |
| 3253 static void Copy(uint8_t* dst, | |
| 3254 const ByteArray& src, | |
| 3255 intptr_t src_byte_offset, | |
|
cshapiro
2012/01/27 23:00:04
You can probably shorten src_byte_offset to just s
Anders Johnsen
2012/01/27 23:42:39
Done.
| |
| 3256 intptr_t length); | |
| 3257 | |
| 3258 static void Copy(const ByteArray& dst, | |
| 3259 intptr_t dst_byte_offset, | |
| 3260 const uint8_t* src, | |
| 3261 intptr_t length); | |
| 3262 | |
| 3263 static void Copy(const ByteArray& dst, | |
| 3264 intptr_t dst_byte_offset, | |
| 3265 const ByteArray& src, | |
| 3266 intptr_t src_byte_offset, | |
| 3267 intptr_t length); | |
| 3268 | |
| 3253 private: | 3269 private: |
| 3270 virtual uint8_t* ByteAddr(intptr_t byte_offset) const; | |
| 3271 | |
| 3254 HEAP_OBJECT_IMPLEMENTATION(ByteArray, Instance); | 3272 HEAP_OBJECT_IMPLEMENTATION(ByteArray, Instance); |
| 3255 friend class Class; | 3273 friend class Class; |
| 3256 }; | 3274 }; |
| 3257 | 3275 |
| 3258 | 3276 |
| 3259 class InternalByteArray : public ByteArray { | 3277 class InternalByteArray : public ByteArray { |
| 3260 public: | 3278 public: |
| 3261 intptr_t Length() const { | 3279 intptr_t Length() const { |
| 3262 ASSERT(!IsNull()); | 3280 ASSERT(!IsNull()); |
| 3263 return Smi::Value(raw_ptr()->length_); | 3281 return Smi::Value(raw_ptr()->length_); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3307 return RoundedAllocationSize(sizeof(RawInternalByteArray) + len); | 3325 return RoundedAllocationSize(sizeof(RawInternalByteArray) + len); |
| 3308 } | 3326 } |
| 3309 | 3327 |
| 3310 static RawInternalByteArray* New(intptr_t len, | 3328 static RawInternalByteArray* New(intptr_t len, |
| 3311 Heap::Space space = Heap::kNew); | 3329 Heap::Space space = Heap::kNew); |
| 3312 static RawInternalByteArray* New(const uint8_t* data, | 3330 static RawInternalByteArray* New(const uint8_t* data, |
| 3313 intptr_t len, | 3331 intptr_t len, |
| 3314 Heap::Space space = Heap::kNew); | 3332 Heap::Space space = Heap::kNew); |
| 3315 | 3333 |
| 3316 private: | 3334 private: |
| 3335 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 3336 return Addr<uint8_t>(byte_offset); | |
| 3337 } | |
| 3338 | |
| 3317 template<typename T> | 3339 template<typename T> |
| 3318 T* Addr(intptr_t byte_offset) const { | 3340 T* Addr(intptr_t byte_offset) const { |
| 3319 intptr_t limit = byte_offset + sizeof(T); | 3341 intptr_t limit = byte_offset + sizeof(T); |
| 3320 // TODO(iposva): Determine if we should throw an exception here. | 3342 // TODO(iposva): Determine if we should throw an exception here. |
| 3321 ASSERT((byte_offset >= 0) && (limit <= Length())); | 3343 ASSERT((byte_offset >= 0) && (limit <= Length())); |
| 3322 uint8_t* addr = &raw_ptr()->data()[byte_offset]; | 3344 uint8_t* addr = &raw_ptr()->data()[byte_offset]; |
| 3323 return reinterpret_cast<T*>(addr); | 3345 return reinterpret_cast<T*>(addr); |
| 3324 } | 3346 } |
| 3325 | 3347 |
| 3326 void SetLength(intptr_t value) { | 3348 void SetLength(intptr_t value) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3367 | 3389 |
| 3368 static intptr_t InstanceSize() { | 3390 static intptr_t InstanceSize() { |
| 3369 return RoundedAllocationSize(sizeof(RawExternalByteArray)); | 3391 return RoundedAllocationSize(sizeof(RawExternalByteArray)); |
| 3370 } | 3392 } |
| 3371 | 3393 |
| 3372 static RawExternalByteArray* New(uint8_t* data, | 3394 static RawExternalByteArray* New(uint8_t* data, |
| 3373 intptr_t len, | 3395 intptr_t len, |
| 3374 Heap::Space space = Heap::kNew); | 3396 Heap::Space space = Heap::kNew); |
| 3375 | 3397 |
| 3376 private: | 3398 private: |
| 3399 uint8_t* ByteAddr(intptr_t byte_offset) const { | |
| 3400 return Addr<uint8_t>(byte_offset); | |
| 3401 } | |
| 3402 | |
| 3377 template<typename T> | 3403 template<typename T> |
| 3378 T* Addr(intptr_t byte_offset) const { | 3404 T* Addr(intptr_t byte_offset) const { |
| 3379 intptr_t limit = byte_offset + sizeof(T); | 3405 intptr_t limit = byte_offset + sizeof(T); |
| 3380 // TODO(iposva): Determine if we should throw an exception here. | 3406 // TODO(iposva): Determine if we should throw an exception here. |
| 3381 ASSERT((byte_offset >= 0) && (limit <= Length())); | 3407 ASSERT((byte_offset >= 0) && (limit <= Length())); |
| 3382 uint8_t* addr = &raw_ptr()->data_[byte_offset]; | 3408 uint8_t* addr = &raw_ptr()->data_[byte_offset]; |
| 3383 return reinterpret_cast<T*>(addr); | 3409 return reinterpret_cast<T*>(addr); |
| 3384 } | 3410 } |
| 3385 | 3411 |
| 3386 void SetLength(intptr_t value) { | 3412 void SetLength(intptr_t value) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3602 } | 3628 } |
| 3603 | 3629 |
| 3604 | 3630 |
| 3605 void Context::SetAt(intptr_t index, const Instance& value) const { | 3631 void Context::SetAt(intptr_t index, const Instance& value) const { |
| 3606 StorePointer(InstanceAddr(index), value.raw()); | 3632 StorePointer(InstanceAddr(index), value.raw()); |
| 3607 } | 3633 } |
| 3608 | 3634 |
| 3609 } // namespace dart | 3635 } // namespace dart |
| 3610 | 3636 |
| 3611 #endif // VM_OBJECT_H_ | 3637 #endif // VM_OBJECT_H_ |
| OLD | NEW |