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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 4647 matching lines...) Expand 10 before | Expand all | Expand 10 after
4658 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength())); 4658 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
4659 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset; 4659 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset;
4660 } 4660 }
4661 4661
4662 HEAP_OBJECT_IMPLEMENTATION(Uint8Array, ByteArray); 4662 HEAP_OBJECT_IMPLEMENTATION(Uint8Array, ByteArray);
4663 friend class ByteArray; 4663 friend class ByteArray;
4664 friend class Class; 4664 friend class Class;
4665 }; 4665 };
4666 4666
4667 4667
4668 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.
4669 public:
4670 intptr_t ByteLength() const {
4671 return Length();
4672 }
4673
4674 uint8_t At(intptr_t index) const {
4675 ASSERT((index >= 0) && (index < Length()));
4676 return raw_ptr()->data_[index];
4677 }
4678
4679 void SetAt(intptr_t index, uint8_t value) const {
4680 ASSERT((index >= 0) && (index < Length()));
4681 raw_ptr()->data_[index] = value;
4682 }
4683
4684 static const intptr_t kBytesPerElement = 1;
4685 static const intptr_t kMaxElements = kSmiMax / kBytesPerElement;
4686
4687 static intptr_t data_offset() {
4688 return OFFSET_OF(RawUint8ClampedArray, data_);
4689 }
4690
4691 static intptr_t InstanceSize() {
4692 ASSERT(sizeof(RawUint8ClampedArray) ==
4693 OFFSET_OF(RawUint8ClampedArray, data_));
4694 return 0;
4695 }
4696
4697 static intptr_t InstanceSize(intptr_t len) {
4698 ASSERT(0 <= len && len <= kMaxElements);
4699 return RoundedAllocationSize(
4700 sizeof(RawUint8ClampedArray) + (len * kBytesPerElement));
4701 }
4702
4703 static RawUint8ClampedArray* New(intptr_t len,
4704 Heap::Space space = Heap::kNew);
4705 static RawUint8ClampedArray* New(const uint8_t* data,
4706 intptr_t len,
4707 Heap::Space space = Heap::kNew);
4708
4709 private:
4710 uint8_t* ByteAddr(intptr_t byte_offset) const {
4711 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
4712 return reinterpret_cast<uint8_t*>(&raw_ptr()->data_) + byte_offset;
4713 }
4714
4715 HEAP_OBJECT_IMPLEMENTATION(Uint8ClampedArray, ByteArray);
4716 friend class ByteArray;
4717 friend class Class;
4718 };
4719
4720
4668 class Int16Array : public ByteArray { 4721 class Int16Array : public ByteArray {
4669 public: 4722 public:
4670 intptr_t ByteLength() const { 4723 intptr_t ByteLength() const {
4671 return Length() * kBytesPerElement; 4724 return Length() * kBytesPerElement;
4672 } 4725 }
4673 4726
4674 int16_t At(intptr_t index) const { 4727 int16_t At(intptr_t index) const {
4675 ASSERT((index >= 0) && (index < Length())); 4728 ASSERT((index >= 0) && (index < Length()));
4676 return raw_ptr()->data_[index]; 4729 return raw_ptr()->data_[index];
4677 } 4730 }
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
5195 raw_ptr()->external_data_ = data; 5248 raw_ptr()->external_data_ = data;
5196 } 5249 }
5197 5250
5198 HEAP_OBJECT_IMPLEMENTATION(ExternalUint8Array, ByteArray); 5251 HEAP_OBJECT_IMPLEMENTATION(ExternalUint8Array, ByteArray);
5199 friend class ByteArray; 5252 friend class ByteArray;
5200 friend class Class; 5253 friend class Class;
5201 friend class TokenStream; 5254 friend class TokenStream;
5202 }; 5255 };
5203 5256
5204 5257
5258 class ExternalUint8ClampedArray : public ByteArray {
5259 public:
5260 intptr_t ByteLength() const {
5261 return Length() * kBytesPerElement;
5262 }
5263
5264 uint8_t At(intptr_t index) const {
5265 ASSERT((index >= 0) && (index < Length()));
5266 return raw_ptr()->external_data_->data()[index];
5267 }
5268
5269 void SetAt(intptr_t index, uint8_t value) const {
5270 ASSERT((index >= 0) && (index < Length()));
5271 raw_ptr()->external_data_->data()[index] = value;
5272 }
5273
5274 void* GetData() const {
5275 return raw_ptr()->external_data_->data();
5276 }
5277
5278 void* GetPeer() const {
5279 return raw_ptr()->external_data_->peer();
5280 }
5281
5282 static const intptr_t kBytesPerElement = 1;
5283
5284 // Since external arrays may be serialized to non-external ones,
5285 // enforce the same maximum element count.
5286 static const intptr_t kMaxElements = Uint8ClampedArray::kMaxElements;
5287
5288 static intptr_t InstanceSize() {
5289 return RoundedAllocationSize(sizeof(RawExternalUint8ClampedArray));
5290 }
5291
5292 static intptr_t external_data_offset() {
5293 return OFFSET_OF(RawExternalUint8ClampedArray, external_data_);
5294 }
5295
5296 static RawExternalUint8ClampedArray* New(uint8_t* data,
5297 intptr_t len,
5298 void* peer,
5299 Dart_PeerFinalizer callback,
5300 Heap::Space space = Heap::kNew);
5301
5302 private:
5303 uint8_t* ByteAddr(intptr_t byte_offset) const {
5304 ASSERT((byte_offset >= 0) && (byte_offset < ByteLength()));
5305 uint8_t* data =
5306 reinterpret_cast<uint8_t*>(raw_ptr()->external_data_->data());
5307 return data + byte_offset;
5308 }
5309
5310 void SetExternalData(ExternalByteArrayData<uint8_t>* data) {
5311 raw_ptr()->external_data_ = data;
5312 }
5313
5314 HEAP_OBJECT_IMPLEMENTATION(ExternalUint8ClampedArray, ByteArray);
5315 friend class ByteArray;
5316 friend class Class;
5317 friend class TokenStream;
5318 };
5319
5320
5205 class ExternalInt16Array : public ByteArray { 5321 class ExternalInt16Array : public ByteArray {
5206 public: 5322 public:
5207 intptr_t ByteLength() const { 5323 intptr_t ByteLength() const {
5208 return Length() * kBytesPerElement; 5324 return Length() * kBytesPerElement;
5209 } 5325 }
5210 5326
5211 int16_t At(intptr_t index) const { 5327 int16_t At(intptr_t index) const {
5212 ASSERT((index >= 0) && (index < Length())); 5328 ASSERT((index >= 0) && (index < Length()));
5213 return raw_ptr()->external_data_->data()[index]; 5329 return raw_ptr()->external_data_->data()[index];
5214 } 5330 }
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
5993 if (this->CharAt(i) != str.CharAt(begin_index + i)) { 6109 if (this->CharAt(i) != str.CharAt(begin_index + i)) {
5994 return false; 6110 return false;
5995 } 6111 }
5996 } 6112 }
5997 return true; 6113 return true;
5998 } 6114 }
5999 6115
6000 } // namespace dart 6116 } // namespace dart
6001 6117
6002 #endif // VM_OBJECT_H_ 6118 #endif // VM_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698