Skip to content

Commit 813a536

Browse files
thlorenzbnoordhuis
authored andcommitted
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: if (length == 0) return Alloc(env, obj, nullptr, length, type); char* data = static_cast<char*>(malloc(length)); if (data == nullptr) { FatalError("node::smalloc::Alloc(v8::Handle<v8::Object>, size_t," " v8::ExternalArrayType)", "Out Of Memory"); } Alloc(env, obj, data, length, type); PR-URL: #1144 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent 1514b82 commit 813a536

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

src/node_buffer.cc

+1-12
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,7 @@ Local<Object> New(Environment* env, size_t length) {
123123
Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length);
124124
Local<Object> obj = env->buffer_constructor_function()->NewInstance(1, &arg);
125125

126-
// TODO(trevnorris): done like this to handle HasInstance since only checks
127-
// if external array data has been set, but would like to use a better
128-
// approach if v8 provided one.
129-
char* data;
130-
if (length > 0) {
131-
data = static_cast<char*>(malloc(length));
132-
if (data == nullptr)
133-
FatalError("node::Buffer::New(size_t)", "Out Of Memory");
134-
} else {
135-
data = nullptr;
136-
}
137-
smalloc::Alloc(env, obj, data, length);
126+
smalloc::Alloc(env, obj, length);
138127

139128
return scope.Escape(obj);
140129
}

0 commit comments

Comments
 (0)