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

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: Make loads and stores byte relative Created 9 years, 1 month 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 d4bdb64ca90fc5fb24f7852c93542044173621bd..8fcd9c0198b7c0f4af13597aa22aa6cbeeeeb219 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<ByteBuffer>();
+ object_store->set_byte_buffer_class(cls);
+
cls = Class::New<UnhandledException>();
object_store->set_unhandled_exception_class(cls);
@@ -527,6 +530,12 @@ void Object::Init(Isolate* isolate) {
cls.set_script(script);
core_lib.AddClass(cls);
+ name = String::NewSymbol("ByteBuffer");
+ cls = object_store->byte_buffer_class();
+ cls.set_name(name);
+ cls.set_script(script);
+ core_lib.AddClass(cls);
+
name = String::NewSymbol("Function");
cls = Class::NewInterface(name, script);
core_lib.AddClass(cls);
@@ -625,6 +634,9 @@ void Object::InitFromSnapshot(Isolate* isolate) {
cls = Class::New<ImmutableArray>();
object_store->set_immutable_array_class(cls);
+ cls = Class::New<ByteBuffer>();
+ object_store->set_byte_buffer_class(cls);
+
cls = Class::New<Instance>();
object_store->set_object_class(cls);
@@ -1109,6 +1121,9 @@ RawClass* Class::GetClass(ObjectKind kind) {
case kImmutableArray:
ASSERT(object_store->immutable_array_class() != Class::null());
return object_store->immutable_array_class();
+ case kByteBuffer:
+ ASSERT(object_store->byte_buffer_class() != Class::null());
+ return object_store->byte_buffer_class();
case kStacktrace:
ASSERT(object_store->stacktrace_class() != Class::null());
return object_store->stacktrace_class();
@@ -6642,6 +6657,53 @@ const char* ImmutableArray::ToCString() const {
}
+RawByteBuffer* ByteBuffer::New(uint8_t* data,
+ intptr_t len,
+ Heap::Space space) {
+ Isolate* isolate = Isolate::Current();
+ const Class& byte_buffer_class =
+ Class::Handle(isolate->object_store()->byte_buffer_class());
+ ByteBuffer& result = ByteBuffer::Handle();
+ {
+ RawObject* raw = Object::Allocate(byte_buffer_class,
+ ByteBuffer::InstanceSize(),
+ space);
+ NoGCScope no_gc;
+ result ^= raw;
+ result.SetLength(len);
+ result.SetData(data);
+ }
+ return result.raw();
+}
+
+
+bool ByteBuffer::Equals(const Instance& other) const {
+ if (this->raw() == other.raw()) {
+ // Both handles point to the same raw instance.
+ return true;
+ }
+
+ if (!other.IsByteBuffer() || other.IsNull()) {
+ return false;
+ }
+
+ ByteBuffer& other_array = ByteBuffer::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* ByteBuffer::ToCString() const {
+ return "ByteBuffer";
+}
+
+
RawClosure* Closure::New(const Function& function,
const Context& context,
Heap::Space space) {

Powered by Google App Engine
This is Rietveld 408576698