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

Unified Diff: runtime/vm/object.cc

Issue 8429027: Add an external array type to support typed arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 2 months 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.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 9d90a3544f20fb3a9896bbda70240303d09b0d47..8f5750cea4a7b1456fe06c71da7a9d5509313f26 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -397,6 +397,9 @@ void Object::Init(Isolate* isolate) {
cls = Class::New<Bool>();
object_store->set_bool_class(cls);
+ cls = Class::New<ExternalArray>();
+ object_store->set_external_array_class(cls);
+
cls = Class::New<UnhandledException>();
object_store->set_unhandled_exception_class(cls);
@@ -626,6 +629,9 @@ void Object::InitFromSnapshot(Isolate* isolate) {
cls = Class::New<ImmutableArray>();
object_store->set_immutable_array_class(cls);
+ cls = Class::New<ExternalArray>();
+ object_store->set_external_array_class(cls);
+
cls = Class::New<Instance>();
object_store->set_object_class(cls);
@@ -1109,6 +1115,9 @@ RawClass* Class::GetClass(ObjectKind kind) {
case kImmutableArray:
ASSERT(object_store->immutable_array_class() != Class::null());
return object_store->immutable_array_class();
+ case kExternalArray:
+ ASSERT(object_store->external_array_class() != Class::null());
+ return object_store->external_array_class();
case kStacktrace:
ASSERT(object_store->stacktrace_class() != Class::null());
return object_store->stacktrace_class();
@@ -6503,6 +6512,53 @@ const char* ImmutableArray::ToCString() const {
}
+RawExternalArray* ExternalArray::New(uint8_t* data,
+ intptr_t len,
+ Heap::Space space) {
+ Isolate* isolate = Isolate::Current();
+ const Class& external_array_class =
+ Class::Handle(isolate->object_store()->external_array_class());
+ ExternalArray& result = ExternalArray::Handle();
+ {
+ RawObject* raw = Object::Allocate(external_array_class,
+ ExternalArray::InstanceSize(),
+ space);
+ NoGCScope no_gc;
+ result ^= raw;
+ result.SetLength(len);
+ result.SetData(data);
+ }
+ return result.raw();
+}
+
+
+bool ExternalArray::Equals(const Instance& other) const {
+ if (this->raw() == other.raw()) {
+ // Both handles point to the same raw instance.
+ return true;
+ }
+
+ if (!other.IsExternalArray() || other.IsNull()) {
+ return false;
+ }
+
+ ExternalArray& other_array = ExternalArray::Handle();
+ other_array ^= other.raw();
+
+ intptr_t len = this->Length();
+ if (len != other_array.Length()) {
+ return false;
+ }
+
+ return !memcmp(this->Addr<uint8_t>(0), other_array.Addr<uint8_t>(0), len);
+}
+
+
+const char* ExternalArray::ToCString() const {
+ return "ExternalArray";
+}
+
+
RawClosure* Closure::New(const Function& function,
const Context& context,
Heap::Space space) {

Powered by Google App Engine
This is Rietveld 408576698