Chromium Code Reviews| Index: runtime/vm/object.cc |
| diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
| index 4b7e87d6a1445aa1c7d1a0318caa6832008c2276..3025a03128fb39ec5d75388d5e49d6e7f5aaf31f 100644 |
| --- a/runtime/vm/object.cc |
| +++ b/runtime/vm/object.cc |
| @@ -534,7 +534,7 @@ void Object::Init(Isolate* isolate) { |
| const Script& script = Script::Handle(Bootstrap::LoadScript()); |
| // Allocate and initialize the Object class and type. |
| - // The Object and ByteBuffer classes are the only pre-allocated |
| + // The Object and ExternalByteArray classes are the only pre-allocated |
| // non-interface classes in the core library. |
| cls = Class::New<Instance>(); |
| object_store->set_object_class(cls); |
| @@ -545,9 +545,15 @@ 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 = Class::New<InternalByteArray>(); |
| + object_store->set_internal_byte_array_class(cls); |
| + cls.set_name(String::Handle(String::NewSymbol("InternalByteArray"))); |
| + cls.set_script(script); |
| + core_lib.AddClass(cls); |
| + |
| + cls = Class::New<ExternalByteArray>(); |
| + object_store->set_external_byte_array_class(cls); |
| + cls.set_name(String::Handle(String::NewSymbol("ExternalByteArray"))); |
| cls.set_script(script); |
| core_lib.AddClass(cls); |
| @@ -591,6 +597,11 @@ void Object::Init(Isolate* isolate) { |
| type = Type::NewNonParameterizedType(cls); |
| object_store->set_list_interface(type); |
| + cls = CreateAndRegisterInterface("ByteArray", script, core_lib); |
| + pending_classes.Add(&Class::ZoneHandle(cls.raw())); |
| + type = Type::NewNonParameterizedType(cls); |
| + object_store->set_byte_array_interface(type); |
| + |
| // The classes 'Null' and 'void' are not registered in the class dictionary, |
| // because their names are reserved keywords. Their names are not heap |
| // allocated, because the classes reside in the VM isolate. |
| @@ -662,8 +673,11 @@ 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<InternalByteArray>(); |
| + object_store->set_internal_byte_array_class(cls); |
| + |
| + cls = Class::New<ExternalByteArray>(); |
| + object_store->set_external_byte_array_class(cls); |
| cls = Class::New<Instance>(); |
| object_store->set_object_class(cls); |
| @@ -1221,9 +1235,12 @@ 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 kInternalByteArray: |
| + ASSERT(object_store->internal_byte_array_class() != Class::null()); |
| + return object_store->internal_byte_array_class(); |
| + case kExternalByteArray: |
| + ASSERT(object_store->external_byte_array_class() != Class::null()); |
| + return object_store->external_byte_array_class(); |
| case kStacktrace: |
| ASSERT(object_store->stacktrace_class() != Class::null()); |
| return object_store->stacktrace_class(); |
| @@ -7359,16 +7376,84 @@ const char* ImmutableArray::ToCString() const { |
| } |
| -RawByteBuffer* ByteBuffer::New(uint8_t* data, |
| - intptr_t len, |
| - Heap::Space space) { |
| +intptr_t ByteArray::Length() const { |
| + // ByteArray is an abstract class. |
| + UNREACHABLE(); |
| + return 0; |
| +} |
| + |
| + |
| +const char* ByteArray::ToCString() const { |
| + // ByteArray is an abstract class. |
| + UNREACHABLE(); |
| + return "ByteArray"; |
| +} |
| + |
| + |
| +bool InternalByteArray::Equals(const Instance& that) const { |
| + if (this->raw() == that.raw()) { |
| + // Both handles point to the same raw instance. |
| + return true; |
| + } |
| + if (!that.IsInternalByteArray() || that.IsNull()) { |
| + return false; |
|
siva
2012/01/20 22:51:04
So we can't check if an internal byte array is equ
cshapiro
2012/01/24 02:14:23
I have removed the equality checks. They do not m
|
| + } |
| + InternalByteArray& that_array = InternalByteArray::Handle(); |
| + that_array ^= that.raw(); |
| + intptr_t len = this->Length(); |
| + if (len != that_array.Length()) { |
| + return false; |
| + } |
| + return memcmp(this->Addr<uint8_t>(0), that_array.Addr<uint8_t>(0), len) == 0; |
| +} |
| + |
| + |
| +RawInternalByteArray* InternalByteArray::New(intptr_t len, |
| + Heap::Space space) { |
| + Isolate* isolate = Isolate::Current(); |
| + const Class& internal_byte_array_class = |
| + Class::Handle(isolate->object_store()->internal_byte_array_class()); |
| + InternalByteArray& result = InternalByteArray::Handle(); |
| + { |
| + RawObject* raw = Object::Allocate(internal_byte_array_class, |
| + InternalByteArray::InstanceSize(len), |
| + space); |
| + NoGCScope no_gc; |
| + result ^= raw; |
| + result.SetLength(len); |
| + } |
| + return result.raw(); |
| +} |
| + |
| + |
| +RawInternalByteArray* InternalByteArray::New(const uint8_t* data, |
| + intptr_t len, |
| + Heap::Space space) { |
| + InternalByteArray& result = |
| + InternalByteArray::Handle(InternalByteArray::New(len, space)); |
| + { |
| + NoGCScope no_gc; |
| + memmove(result.Addr<uint8_t>(0), data, len); |
| + } |
| + return result.raw(); |
| +} |
| + |
| + |
| +const char* InternalByteArray::ToCString() const { |
| + return "InternalByteArray"; |
| +} |
| + |
| + |
| +RawExternalByteArray* ExternalByteArray::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(); |
| + const Class& external_byte_array_class = |
| + Class::Handle(isolate->object_store()->external_byte_array_class()); |
| + ExternalByteArray& result = ExternalByteArray::Handle(); |
| { |
| - RawObject* raw = Object::Allocate(byte_buffer_class, |
| - ByteBuffer::InstanceSize(), |
| + RawObject* raw = Object::Allocate(external_byte_array_class, |
| + ExternalByteArray::InstanceSize(), |
| space); |
| NoGCScope no_gc; |
| result ^= raw; |
| @@ -7379,17 +7464,17 @@ RawByteBuffer* ByteBuffer::New(uint8_t* data, |
| } |
| -bool ByteBuffer::Equals(const Instance& other) const { |
| +bool ExternalByteArray::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()) { |
| + if (!other.IsExternalByteArray() || other.IsNull()) { |
| return false; |
| } |
|
siva
2012/01/20 22:51:04
Ditto comment about comparing with an internal byt
cshapiro
2012/01/24 02:14:23
Same here. Gone.
|
| - ByteBuffer& other_array = ByteBuffer::Handle(); |
| + ExternalByteArray& other_array = ExternalByteArray::Handle(); |
| other_array ^= other.raw(); |
| intptr_t len = this->Length(); |
| @@ -7401,8 +7486,8 @@ bool ByteBuffer::Equals(const Instance& other) const { |
| } |
| -const char* ByteBuffer::ToCString() const { |
| - return "ByteBuffer"; |
| +const char* ExternalByteArray::ToCString() const { |
| + return "ExternalByteArray"; |
| } |