Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6fdc502

Browse filesBrowse files
committed
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: #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>
1 parent 51f01aa commit 6fdc502
Copy full SHA for 6fdc502

File tree

Expand file treeCollapse file tree

2 files changed

+6
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+6
-11
lines changed
Open diff view settings
Collapse file

‎src/node_messaging.cc‎

Copy file name to clipboardExpand all lines: src/node_messaging.cc
+5-10Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,18 +469,18 @@ MessagePort::MessagePort(Environment* env,
469469
Local<Object> wrap)
470470
: HandleWrap(env,
471471
wrap,
472-
reinterpret_cast<uv_handle_t*>(new uv_async_t()),
472+
reinterpret_cast<uv_handle_t*>(&async_),
473473
AsyncWrap::PROVIDER_MESSAGEPORT),
474474
data_(new MessagePortData(this)) {
475475
auto onmessage = [](uv_async_t* handle) {
476476
// Called when data has been put into the queue.
477-
MessagePort* channel = static_cast<MessagePort*>(handle->data);
477+
MessagePort* channel = ContainerOf(&MessagePort::async_, handle);
478478
channel->OnMessage();
479479
};
480480
CHECK_EQ(uv_async_init(env->event_loop(),
481-
async(),
481+
&async_,
482482
onmessage), 0);
483-
async()->data = static_cast<void*>(this);
483+
async_.data = static_cast<void*>(this);
484484

485485
Local<Value> fn;
486486
if (!wrap->Get(context, env->oninit_symbol()).ToLocal(&fn))
@@ -494,17 +494,13 @@ MessagePort::MessagePort(Environment* env,
494494
Debug(this, "Created message port");
495495
}
496496

497-
uv_async_t* MessagePort::async() {
498-
return reinterpret_cast<uv_async_t*>(GetHandle());
499-
}
500-
501497
bool MessagePort::IsDetached() const {
502498
return data_ == nullptr || IsHandleClosing();
503499
}
504500

505501
void MessagePort::TriggerAsync() {
506502
if (IsHandleClosing()) return;
507-
CHECK_EQ(uv_async_send(async()), 0);
503+
CHECK_EQ(uv_async_send(&async_), 0);
508504
}
509505

510506
void MessagePort::Close(v8::Local<v8::Value> close_callback) {
@@ -639,7 +635,6 @@ void MessagePort::OnClose() {
639635
data_->Disentangle();
640636
}
641637
data_.reset();
642-
delete async();
643638
}
644639

645640
std::unique_ptr<MessagePortData> MessagePort::Detach() {
Collapse file

‎src/node_messaging.h‎

Copy file name to clipboardExpand all lines: src/node_messaging.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ class MessagePort : public HandleWrap {
198198
void OnClose() override;
199199
void OnMessage();
200200
void TriggerAsync();
201-
inline uv_async_t* async();
202201

203202
std::unique_ptr<MessagePortData> data_ = nullptr;
203+
uv_async_t async_;
204204

205205
friend class MessagePortData;
206206
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.