Chromium Code Reviews| Index: runtime/vm/object.h |
| diff --git a/runtime/vm/object.h b/runtime/vm/object.h |
| index a5676a34f7f26cb853a2008a1d241f6281f5f82b..9b2d1247fb3aafa2fca3cb86c3624c55a7555ca1 100644 |
| --- a/runtime/vm/object.h |
| +++ b/runtime/vm/object.h |
| @@ -2763,6 +2763,117 @@ class ImmutableArray : public Array { |
| }; |
| +class ExternalArray : public Instance { |
| + public: |
| + intptr_t Length() const { |
| + ASSERT(!IsNull()); |
| + return Smi::Value(raw_ptr()->length_); |
| + } |
| + |
| + int8_t Int8At(intptr_t index) const { |
| + return *Addr<int8_t>(index); |
| + } |
| + void SetInt8At(intptr_t index, int8_t value) const { |
| + *Addr<int8_t>(index) = value; |
| + } |
| + |
| + uint8_t Uint8At(intptr_t index) const { |
| + return *Addr<uint8_t>(index); |
| + } |
| + void SetUint8At(intptr_t index, uint8_t value) const { |
| + *Addr<uint8_t>(index) = value; |
| + } |
| + |
| + int16_t Int16At(intptr_t index) const { |
| + return *Addr<int16_t>(index); |
| + } |
| + void SetInt16At(intptr_t index, int16_t value) const { |
| + *Addr<int16_t>(index) = value; |
| + } |
| + |
| + uint16_t Uint16At(intptr_t index) const { |
| + return *Addr<uint16_t>(index); |
| + } |
| + void SetUint16At(intptr_t index, uint16_t value) const { |
| + *Addr<uint16_t>(index) = value; |
| + } |
| + |
| + int32_t Int32At(intptr_t index) const { |
| + return *Addr<int32_t>(index); |
| + } |
| + void SetInt32At(intptr_t index, int32_t value) const { |
| + *Addr<int32_t>(index) = value; |
| + } |
| + |
| + uint32_t Uint32At(intptr_t index) const { |
| + return *Addr<uint32_t>(index); |
| + } |
| + void SetUint32At(intptr_t index, uint32_t value) const { |
| + *Addr<uint32_t>(index) = value; |
| + } |
| + |
| + int64_t Int64At(intptr_t index) const { |
| + return *Addr<int64_t>(index); |
| + } |
| + void SetInt64At(intptr_t index, int64_t value) const { |
| + *Addr<int64_t>(index) = value; |
| + } |
| + |
| + uint64_t Uint64At(intptr_t index) const { |
| + return *Addr<uint64_t>(index); |
| + } |
| + void SetUint64At(intptr_t index, uint64_t value) const { |
| + *Addr<uint64_t>(index) = value; |
| + } |
| + |
| + float Float32At(intptr_t index) const { |
| + return *Addr<float>(index); |
| + } |
| + void SetFloat32At(intptr_t index, float value) const { |
| + *Addr<float>(index) = value; |
| + } |
| + |
| + double Float64At(intptr_t index) const { |
| + return *Addr<double>(index); |
| + } |
| + void SetFloat64At(intptr_t index, double value) const { |
| + *Addr<double>(index) = value; |
| + } |
| + |
| + virtual bool Equals(const Instance& other) const; |
| + |
| + static intptr_t InstanceSize() { |
| + return RoundedAllocationSize(sizeof(RawExternalArray)); |
| + } |
| + |
| + static RawExternalArray* New(uint8_t* data, |
| + intptr_t len, |
| + Heap::Space space = Heap::kNew); |
| + |
| + private: |
| + template<typename T> |
| + T* Addr(intptr_t index) const { |
| + intptr_t byte_start = index / sizeof(T); |
|
siva
2011/11/02 17:05:31
is this right:
for instance Addr<int32_t>(1) shou
cshapiro
2011/11/04 18:16:21
No, it was not. I fixed this in the more recent p
|
| + intptr_t byte_end = byte_start + sizeof(T); |
| + // TODO(iposva): Determine if we should throw an exception here. |
| + ASSERT((byte_start >= 0) && (byte_end < Length())); |
| + uint8_t* addr = &raw_ptr()->data_[byte_start]; |
| + return reinterpret_cast<T*>(addr); |
| + } |
| + |
| + void SetLength(intptr_t value) { |
| + raw_ptr()->length_ = Smi::New(value); |
| + } |
| + |
| + void SetData(uint8_t* data) const { |
| + raw_ptr()->data_ = data; |
| + } |
| + |
| + HEAP_OBJECT_IMPLEMENTATION(ExternalArray, Instance); |
| + friend class Class; |
| +}; |
| + |
| + |
| class Closure : public Instance { |
| public: |
| RawFunction* function() const { return raw_ptr()->function_; } |