Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Simplify things by using *ArrayData everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphan Kochen authored and ry committed Oct 22, 2010
1 parent d9b08d6 commit d5e9661
Showing 1 changed file with 8 additions and 33 deletions.
41 changes: 8 additions & 33 deletions src/node_buffer.cc
Expand Up @@ -107,35 +107,15 @@ Buffer* Buffer::New(char* data, size_t len) {


char* Buffer::Data(Handle<Object> obj) {
if (obj->HasIndexedPropertiesInPixelData()) {
return (char*)obj->GetIndexedPropertiesPixelData();
}

HandleScope scope;

// Return true for "SlowBuffer"
if (constructor_template->HasInstance(obj)) {
return ObjectWrap::Unwrap<Buffer>(obj)->data_;
}

// Not a buffer.
if (Buffer::HasInstance(obj))
return (char*)obj->GetIndexedPropertiesExternalArrayData();
return NULL;
}


size_t Buffer::Length(Handle<Object> obj) {
if (obj->HasIndexedPropertiesInPixelData()) {
return (size_t)obj->GetIndexedPropertiesPixelDataLength();
}

HandleScope scope;

// Return true for "SlowBuffer"
if (constructor_template->HasInstance(obj)) {
return ObjectWrap::Unwrap<Buffer>(obj)->length_;
}

// Not a buffer.
if (Buffer::HasInstance(obj))
return (size_t)obj->GetIndexedPropertiesExternalArrayDataLength();
return 0;
}

Expand Down Expand Up @@ -584,8 +564,9 @@ Handle<Value> Buffer::MakeFastBuffer(const Arguments &args) {
uint32_t offset = args[2]->Uint32Value();
uint32_t length = args[3]->Uint32Value();

fast_buffer->SetIndexedPropertiesToPixelData((uint8_t*)buffer->data_ + offset,
length);
fast_buffer->SetIndexedPropertiesToExternalArrayData(buffer->data_ + offset,
kExternalUnsignedByteArray,
length);

return Undefined();
}
Expand All @@ -594,13 +575,7 @@ Handle<Value> Buffer::MakeFastBuffer(const Arguments &args) {
bool Buffer::HasInstance(v8::Handle<v8::Value> val) {
if (!val->IsObject()) return false;
v8::Local<v8::Object> obj = val->ToObject();

if (obj->HasIndexedPropertiesInPixelData()) return true;

// Return true for "SlowBuffer"
if (constructor_template->HasInstance(obj)) return true;

return false;
return obj->GetIndexedPropertiesExternalArrayDataType() == kExternalUnsignedByteArray;
}


Expand Down

0 comments on commit d5e9661

Please sign in to comment.