diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-02-23 03:24:09 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-01 23:44:05 +0300 |
commit | 0fc40c8049d0c723d75cf79f24b2aeb28a67af25 (patch) | |
tree | 41806676b3bfd4f821f6e168b9392695f8650a93 /src/node_messaging.cc | |
parent | 4dd7c4b2e4ed9d70d4220380dde81b60c50faed0 (diff) |
worker: make MessagePort `uv_async_t` inline field
It’s not obvious why this was a heap allocation in the first place,
but it’s unneccessary. Most other `HandleWrap`s also store the
libuv handle directly.
PR-URL: https://github.com/nodejs/node/pull/26271
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Diffstat (limited to 'src/node_messaging.cc')
-rw-r--r-- | src/node_messaging.cc | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/node_messaging.cc b/src/node_messaging.cc index c9be44f4102..d727f270633 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -469,18 +469,18 @@ MessagePort::MessagePort(Environment* env, Local<Object> wrap) : HandleWrap(env, wrap, - reinterpret_cast<uv_handle_t*>(new uv_async_t()), + reinterpret_cast<uv_handle_t*>(&async_), AsyncWrap::PROVIDER_MESSAGEPORT), data_(new MessagePortData(this)) { auto onmessage = [](uv_async_t* handle) { // Called when data has been put into the queue. - MessagePort* channel = static_cast<MessagePort*>(handle->data); + MessagePort* channel = ContainerOf(&MessagePort::async_, handle); channel->OnMessage(); }; CHECK_EQ(uv_async_init(env->event_loop(), - async(), + &async_, onmessage), 0); - async()->data = static_cast<void*>(this); + async_.data = static_cast<void*>(this); Local<Value> fn; if (!wrap->Get(context, env->oninit_symbol()).ToLocal(&fn)) @@ -494,17 +494,13 @@ MessagePort::MessagePort(Environment* env, Debug(this, "Created message port"); } -uv_async_t* MessagePort::async() { - return reinterpret_cast<uv_async_t*>(GetHandle()); -} - bool MessagePort::IsDetached() const { return data_ == nullptr || IsHandleClosing(); } void MessagePort::TriggerAsync() { if (IsHandleClosing()) return; - CHECK_EQ(uv_async_send(async()), 0); + CHECK_EQ(uv_async_send(&async_), 0); } void MessagePort::Close(v8::Local<v8::Value> close_callback) { @@ -639,7 +635,6 @@ void MessagePort::OnClose() { data_->Disentangle(); } data_.reset(); - delete async(); } std::unique_ptr<MessagePortData> MessagePort::Detach() { |