summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Lorenz <thlorenz@gmx.de>2015-03-13 15:24:01 -0400
committerBen Noordhuis <info@bnoordhuis.nl>2015-03-19 13:27:35 +0100
commit813a536126a26bd45c0664a49c98d1fc5e0e3c44 (patch)
treed8d3f44c80557d23cbd12ac5e54f94dadc905c54
parent1514b8235540c3ade0e2ab2c1a3ac0b286ea736e (diff)
downloadnodejs-813a536126a26bd45c0664a49c98d1fc5e0e3c44.tar.gz
nodejs-813a536126a26bd45c0664a49c98d1fc5e0e3c44.tar.bz2
nodejs-813a536126a26bd45c0664a49c98d1fc5e0e3c44.zip
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: https://github.com/iojs/io.js/pull/1144 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
-rw-r--r--src/node_buffer.cc13
1 files changed, 1 insertions, 12 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index fa77c0779..7e2096eb1 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -123,18 +123,7 @@ Local<Object> New(Environment* env, size_t length) {
Local<Value> arg = Uint32::NewFromUnsigned(env->isolate(), length);
Local<Object> 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<char*>(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);
}