From 0fc40c8049d0c723d75cf79f24b2aeb28a67af25 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 23 Feb 2019 01:24:09 +0100 Subject: worker: make MessagePort `uv_async_t` inline field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: James M Snell Reviewed-By: Ben Noordhuis Reviewed-By: Gireesh Punathil --- src/node_messaging.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/node_messaging.cc') diff --git a/src/node_messaging.cc b/src/node_messaging.cc index c9be44f410..d727f27063 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -469,18 +469,18 @@ MessagePort::MessagePort(Environment* env, Local wrap) : HandleWrap(env, wrap, - reinterpret_cast(new uv_async_t()), + reinterpret_cast(&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(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(this); + async_.data = static_cast(this); Local 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(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 close_callback) { @@ -639,7 +635,6 @@ void MessagePort::OnClose() { data_->Disentangle(); } data_.reset(); - delete async(); } std::unique_ptr MessagePort::Detach() { -- cgit v1.2.3