diff options
author | murgatroid99 <mlumish@google.com> | 2015-02-13 11:14:03 -0800 |
---|---|---|
committer | murgatroid99 <mlumish@google.com> | 2015-02-13 11:14:03 -0800 |
commit | e012366e25b0e73fdd9e071798e6e0036eadad5d (patch) | |
tree | 6d76dc7008b66eb9c6eba2d814f4a4ed2d21e3f5 /src/node/ext | |
parent | 57dfd058510d1a3be0ce315ff51fb9f793befd64 (diff) |
Improved op_vector memory management
Diffstat (limited to 'src/node/ext')
-rw-r--r-- | src/node/ext/call.cc | 11 | ||||
-rw-r--r-- | src/node/ext/call.h | 7 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index e6701efbd4..a2333fa426 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -49,6 +49,7 @@ using std::unique_ptr; using std::shared_ptr; +using std::vector; namespace grpc { namespace node { @@ -396,7 +397,7 @@ class ServerCloseResponseOp : public Op { int cancelled; }; -tag::tag(NanCallback *callback, std::vector<unique_ptr<Op> > *ops, +tag::tag(NanCallback *callback, OpVec *ops, shared_ptr<Resources> resources) : callback(callback), ops(ops), resources(resources){ } @@ -410,7 +411,7 @@ Handle<Value> GetTagNodeValue(void *tag) { NanEscapableScope(); struct tag *tag_struct = reinterpret_cast<struct tag *>(tag); Handle<Object> tag_obj = NanNew<Object>(); - for (std::vector<unique_ptr<Op> >::iterator it = tag_struct->ops->begin(); + for (vector<unique_ptr<Op> >::iterator it = tag_struct->ops->begin(); it != tag_struct->ops->end(); ++it) { Op *op_ptr = it->get(); tag_obj->Set(op_ptr->GetOpType(), op_ptr->GetNodeValue()); @@ -530,8 +531,8 @@ NAN_METHOD(Call::StartBatch) { Handle<Object> obj = args[0]->ToObject(); Handle<Array> keys = obj->GetOwnPropertyNames(); size_t nops = keys->Length(); - std::vector<grpc_op> ops(nops); - std::vector<unique_ptr<Op> > *op_vector = new std::vector<unique_ptr<Op> >(); + vector<grpc_op> ops(nops); + unique_ptr<OpVec> op_vector(new OpVec()); for (unsigned int i = 0; i < nops; i++) { unique_ptr<Op> op; if (!keys->Get(i)->IsUint32()) { @@ -576,7 +577,7 @@ NAN_METHOD(Call::StartBatch) { NanCallback *callback = new NanCallback(callback_func); grpc_call_error error = grpc_call_start_batch( call->wrapped_call, &ops[0], nops, new struct tag( - callback, op_vector, resources)); + callback, op_vector.release(), resources)); if (error != GRPC_CALL_OK) { return NanThrowError("startBatch failed", error); } diff --git a/src/node/ext/call.h b/src/node/ext/call.h index 4074f1509b..dbdb8e2ff6 100644 --- a/src/node/ext/call.h +++ b/src/node/ext/call.h @@ -43,6 +43,7 @@ #include "channel.h" + namespace grpc { namespace node { @@ -81,12 +82,14 @@ class Op { virtual std::string GetTypeString() const = 0; }; +typedef std::vector<unique_ptr<Op>> OpVec; + struct tag { - tag(NanCallback *callback, std::vector<unique_ptr<Op> > *ops, + tag(NanCallback *callback, OpVec *ops, shared_ptr<Resources> resources); ~tag(); NanCallback *callback; - std::vector<unique_ptr<Op> > *ops; + OpVec *ops; shared_ptr<Resources> resources; }; |