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

Unified Diff: runtime/vm/object.h

Issue 11437028: Added Uint8ClampedList. COmpielr optimziations to follow in next CL. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years 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: runtime/vm/object.h
===================================================================
--- runtime/vm/object.h (revision 15751)
+++ runtime/vm/object.h (working copy)
@@ -4665,6 +4665,59 @@
};
+class Uint8ClampedArray : public ByteArray {
siva 2012/12/06 01:31:13 If we make RawUint8ClampedArray extend RawUint8Arr
srdjan 2012/12/06 19:23:14 Done.
+ public:
+ intptr_t ByteLength() const {
+ return Length();
+ }
+
+ uint8_t At(intptr_t index) const {
+ ASSERT((index >= 0) && (index < Length()));
+ return raw_ptr()->data_[index];
+ }
+
+ void SetAt(intptr_t index, uint8_t value) const {
+ ASSERT((index >= 0) && (index < Length()));
+ raw_ptr()->data_[index] = value;
+ }
+
+ static const intptr_t kBytesPerElement = 1;
+ static const intptr_t kMaxElements = kSmiMax / kBytesPerElement;
+
+ static intptr_t data_offset() {
+ return OFFSET_OF(RawUint8ClampedArray, data_);
+ }
+
+ static intptr_t InstanceSize() {
+ ASSERT(sizeof(RawUint8ClampedArray) ==
+ OFFSET_OF(RawUint8ClampedArray, data_));
+ return 0;
+ }
+
+ static intptr_t InstanceSize(intptr_t len) {
+ ASSERT(0 <= len && len <= kMaxElements);
+ return RoundedAllocationSize(
+ sizeof(RawUint8ClampedArray) + (len * kBytesPerElement));
+ }
+
+ static RawUint8ClampedArray* New(intptr_t len,
+ Heap::Space space = Heap::kNew);
+ static RawUint8ClampedArray* New(const uint8_t* data,
+ intptr_t len,
+ Heap::Space space = Heap::kNew);
+
+ private:
+ uint8_t* ByteAddr(intptr_t byte_offset) const {
+ ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
+ return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset;
+ }
+
+ HEAP_OBJECT_IMPLEMENTATION(Uint8ClampedArray, ByteArray);
+ friend class ByteArray;
+ friend class Class;
+};
+
+
class Int16Array : public ByteArray {
public:
intptr_t ByteLength() const {
@@ -5202,6 +5255,69 @@
};
+class ExternalUint8ClampedArray : public ByteArray {
+ public:
+ intptr_t ByteLength() const {
+ return Length() * kBytesPerElement;
+ }
+
+ uint8_t At(intptr_t index) const {
+ ASSERT((index >= 0) && (index < Length()));
+ return raw_ptr()->external_data_->data()[index];
+ }
+
+ void SetAt(intptr_t index, uint8_t value) const {
+ ASSERT((index >= 0) && (index < Length()));
+ raw_ptr()->external_data_->data()[index] = value;
+ }
+
+ void* GetData() const {
+ return raw_ptr()->external_data_->data();
+ }
+
+ void* GetPeer() const {
+ return raw_ptr()->external_data_->peer();
+ }
+
+ static const intptr_t kBytesPerElement = 1;
+
+ // Since external arrays may be serialized to non-external ones,
+ // enforce the same maximum element count.
+ static const intptr_t kMaxElements = Uint8ClampedArray::kMaxElements;
+
+ static intptr_t InstanceSize() {
+ return RoundedAllocationSize(sizeof(RawExternalUint8ClampedArray));
+ }
+
+ static intptr_t external_data_offset() {
+ return OFFSET_OF(RawExternalUint8ClampedArray, external_data_);
+ }
+
+ static RawExternalUint8ClampedArray* New(uint8_t* data,
+ intptr_t len,
+ void* peer,
+ Dart_PeerFinalizer callback,
+ Heap::Space space = Heap::kNew);
+
+ private:
+ uint8_t* ByteAddr(intptr_t byte_offset) const {
+ ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
+ uint8_t* data =
+ reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data());
+ return data + byte_offset;
+ }
+
+ void SetExternalData(ExternalByteArrayData<uint8_t>* data) {
+ raw_ptr()->external_data_ = data;
+ }
+
+ HEAP_OBJECT_IMPLEMENTATION(ExternalUint8ClampedArray, ByteArray);
+ friend class ByteArray;
+ friend class Class;
+ friend class TokenStream;
+};
+
+
class ExternalInt16Array : public ByteArray {
public:
intptr_t ByteLength() const {

Powered by Google App Engine
This is Rietveld 408576698