From 7a038b89626e03d23ce76b92a76e850a475a7dd3 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Fri, 13 Mar 2015 15:24:01 -0400 Subject: [PATCH] buffer: removing duplicate code - using an overload of Alloc that does the same that was being done inside `Buffer::New` The overload we now call inside `smalloc.cc` takes care of the same as the code that was removed: ```cc if (length == 0) return Alloc(env, obj, nullptr, length, type); char* data = static_cast(malloc(length)); if (data == nullptr) { FatalError("node::smalloc::Alloc(v8::Handle, size_t," " v8::ExternalArrayType)", "Out Of Memory"); } Alloc(env, obj, data, length, type); ``` --- src/node_buffer.cc | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index fa77c0779762a6..7e2096eb1f1307 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -123,18 +123,7 @@ Local New(Environment* env, size_t length) { Local arg = Uint32::NewFromUnsigned(env->isolate(), length); Local obj = env->buffer_constructor_function()->NewInstance(1, &arg); - // TODO(trevnorris): done like this to handle HasInstance since only checks - // if external array data has been set, but would like to use a better - // approach if v8 provided one. - char* data; - if (length > 0) { - data = static_cast(malloc(length)); - if (data == nullptr) - FatalError("node::Buffer::New(size_t)", "Out Of Memory"); - } else { - data = nullptr; - } - smalloc::Alloc(env, obj, data, length); + smalloc::Alloc(env, obj, length); return scope.Escape(obj); }