Browse Source

Simplify things by using `*ArrayData` everywhere.

v0.7.4-release
Stéphan Kochen 14 years ago
committed by Ryan Dahl
parent
commit
d5e966154c
  1. 41
      src/node_buffer.cc

41
src/node_buffer.cc

@ -107,35 +107,15 @@ Buffer* Buffer::New(char* data, size_t len) {
char* Buffer::Data(Handle<Object> obj) { char* Buffer::Data(Handle<Object> obj) {
if (obj->HasIndexedPropertiesInPixelData()) { if (Buffer::HasInstance(obj))
return (char*)obj->GetIndexedPropertiesPixelData(); return (char*)obj->GetIndexedPropertiesExternalArrayData();
}
HandleScope scope;
// Return true for "SlowBuffer"
if (constructor_template->HasInstance(obj)) {
return ObjectWrap::Unwrap<Buffer>(obj)->data_;
}
// Not a buffer.
return NULL; return NULL;
} }
size_t Buffer::Length(Handle<Object> obj) { size_t Buffer::Length(Handle<Object> obj) {
if (obj->HasIndexedPropertiesInPixelData()) { if (Buffer::HasInstance(obj))
return (size_t)obj->GetIndexedPropertiesPixelDataLength(); return (size_t)obj->GetIndexedPropertiesExternalArrayDataLength();
}
HandleScope scope;
// Return true for "SlowBuffer"
if (constructor_template->HasInstance(obj)) {
return ObjectWrap::Unwrap<Buffer>(obj)->length_;
}
// Not a buffer.
return 0; return 0;
} }
@ -584,8 +564,9 @@ Handle<Value> Buffer::MakeFastBuffer(const Arguments &args) {
uint32_t offset = args[2]->Uint32Value(); uint32_t offset = args[2]->Uint32Value();
uint32_t length = args[3]->Uint32Value(); uint32_t length = args[3]->Uint32Value();
fast_buffer->SetIndexedPropertiesToPixelData((uint8_t*)buffer->data_ + offset, fast_buffer->SetIndexedPropertiesToExternalArrayData(buffer->data_ + offset,
length); kExternalUnsignedByteArray,
length);
return Undefined(); return Undefined();
} }
@ -594,13 +575,7 @@ Handle<Value> Buffer::MakeFastBuffer(const Arguments &args) {
bool Buffer::HasInstance(v8::Handle<v8::Value> val) { bool Buffer::HasInstance(v8::Handle<v8::Value> val) {
if (!val->IsObject()) return false; if (!val->IsObject()) return false;
v8::Local<v8::Object> obj = val->ToObject(); v8::Local<v8::Object> obj = val->ToObject();
return obj->GetIndexedPropertiesExternalArrayDataType() == kExternalUnsignedByteArray;
if (obj->HasIndexedPropertiesInPixelData()) return true;
// Return true for "SlowBuffer"
if (constructor_template->HasInstance(obj)) return true;
return false;
} }

Loading…
Cancel
Save