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

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: Address final review comments 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 2908ca1ff038b0131f2fb9fc9d495b476190ce13..0dea4d9102b465f1214b47a7ca9b2c8724d712bc 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -485,7 +485,8 @@ void Object::Init(Isolate* isolate) {
const Script& script = Script::Handle(Bootstrap::LoadScript());
// Allocate and initialize the Object class and type.
- // Object class is the only pre-allocated non-interface in the core library.
+ // The Object and ByteBuffer classes are the only pre-allocated
+ // non-interface classes in the core library.
cls = Class::New<Instance>();
object_store->set_object_class(cls);
cls.set_name(String::Handle(String::NewSymbol("Object")));
@@ -495,6 +496,12 @@ void Object::Init(Isolate* isolate) {
type = Type::NewNonParameterizedType(cls);
object_store->set_object_type(type);
+ cls = Class::New<ByteBuffer>();
+ object_store->set_byte_buffer_class(cls);
+ cls.set_name(String::Handle(String::NewSymbol("ByteBuffer")));
+ cls.set_script(script);
+ core_lib.AddClass(cls);
+
// Set the super type of class Stacktrace to Object type so that the
// 'toString' method is implemented.
cls = object_store->stacktrace_class();
@@ -601,6 +608,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);
@@ -1112,6 +1122,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();
@@ -6698,6 +6711,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) == 0;
+}
+
+
+const char* ByteBuffer::ToCString() const {
+ return "ByteBuffer";
+}
+
+
RawClosure* Closure::New(const Function& function,
const Context& context,
Heap::Space space) {
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698