Skip to content

Commit c51cc9e

Browse files
gengjiawentargos
authored andcommitted
src: apply clang-tidy rule modernize-make-unique
PR-URL: #26493 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 5a29a94 commit c51cc9e

12 files changed

+39
-28
lines changed

src/cares_wrap.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <cerrno>
3232
#include <cstring>
33+
#include <memory>
3334
#include <vector>
3435
#include <unordered_set>
3536

@@ -663,7 +664,7 @@ class QueryWrap : public AsyncWrap {
663664
memcpy(buf_copy, answer_buf, answer_len);
664665
}
665666

666-
wrap->response_data_.reset(new ResponseData());
667+
wrap->response_data_ = std::make_unique<ResponseData>();
667668
ResponseData* data = wrap->response_data_.get();
668669
data->status = status;
669670
data->is_host = false;
@@ -683,7 +684,7 @@ class QueryWrap : public AsyncWrap {
683684
cares_wrap_hostent_cpy(host_copy, host);
684685
}
685686

686-
wrap->response_data_.reset(new ResponseData());
687+
wrap->response_data_ = std::make_unique<ResponseData>();
687688
ResponseData* data = wrap->response_data_.get();
688689
data->status = status;
689690
data->host.reset(host_copy);

src/env.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <algorithm>
2020
#include <atomic>
2121
#include <cstdio>
22+
#include <memory>
2223

2324
namespace node {
2425

@@ -217,8 +218,7 @@ Environment::Environment(IsolateData* isolate_data,
217218

218219
#if HAVE_INSPECTOR
219220
// We can only create the inspector agent after having cloned the options.
220-
inspector_agent_ =
221-
std::unique_ptr<inspector::Agent>(new inspector::Agent(this));
221+
inspector_agent_ = std::make_unique<inspector::Agent>(this);
222222
#endif
223223

224224
AssignToContext(context, ContextInfo(""));
@@ -238,7 +238,8 @@ Environment::Environment(IsolateData* isolate_data,
238238
},
239239
this);
240240

241-
performance_state_.reset(new performance::performance_state(isolate()));
241+
performance_state_ =
242+
std::make_unique<performance::performance_state>(isolate());
242243
performance_state_->Mark(
243244
performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
244245
performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_NODE_START,

src/inspector/main_thread_interface.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <unicode/unistr.h>
88

99
#include <functional>
10+
#include <memory>
1011

1112
namespace node {
1213
namespace inspector {
@@ -114,8 +115,7 @@ class AnotherThreadObjectReference {
114115

115116
~AnotherThreadObjectReference() {
116117
// Disappearing thread may cause a memory leak
117-
thread_->Post(
118-
std::unique_ptr<DeleteRequest>(new DeleteRequest(object_id_)));
118+
thread_->Post(std::make_unique<DeleteRequest>(object_id_));
119119
}
120120

121121
template <typename Fn>
@@ -151,8 +151,7 @@ class MainThreadSessionState {
151151

152152
static std::unique_ptr<MainThreadSessionState> Create(
153153
MainThreadInterface* thread, bool prevent_shutdown) {
154-
return std::unique_ptr<MainThreadSessionState>(
155-
new MainThreadSessionState(thread, prevent_shutdown));
154+
return std::make_unique<MainThreadSessionState>(thread, prevent_shutdown);
156155
}
157156

158157
void Connect(std::unique_ptr<InspectorSessionDelegate> delegate) {

src/inspector/worker_inspector.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include "worker_inspector.h"
2-
32
#include "main_thread_interface.h"
43

4+
#include <memory>
5+
56
namespace node {
67
namespace inspector {
78
namespace {
@@ -88,8 +89,7 @@ void WorkerManager::WorkerStarted(int session_id,
8889
std::unique_ptr<ParentInspectorHandle>
8990
WorkerManager::NewParentHandle(int thread_id, const std::string& url) {
9091
bool wait = !delegates_waiting_on_start_.empty();
91-
return std::unique_ptr<ParentInspectorHandle>(
92-
new ParentInspectorHandle(thread_id, url, thread_, wait));
92+
return std::make_unique<ParentInspectorHandle>(thread_id, url, thread_, wait);
9393
}
9494

9595
void WorkerManager::RemoveAttachDelegate(int id) {
@@ -106,8 +106,7 @@ std::unique_ptr<WorkerManagerEventHandle> WorkerManager::SetAutoAttach(
106106
// Waiting is only reported when a worker is started, same as browser
107107
Report(delegate, worker.second, false);
108108
}
109-
return std::unique_ptr<WorkerManagerEventHandle>(
110-
new WorkerManagerEventHandle(shared_from_this(), id));
109+
return std::make_unique<WorkerManagerEventHandle>(shared_from_this(), id);
111110
}
112111

113112
void WorkerManager::SetWaitOnStartForDelegate(int id, bool wait) {

src/inspector_js_api.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "v8.h"
55
#include "v8-inspector.h"
66

7+
#include <memory>
8+
79
namespace node {
810
namespace inspector {
911
namespace {
@@ -65,8 +67,8 @@ class JSBindingsConnection : public AsyncWrap {
6567
: AsyncWrap(env, wrap, PROVIDER_INSPECTORJSBINDING),
6668
callback_(env->isolate(), callback) {
6769
Agent* inspector = env->inspector_agent();
68-
session_ = inspector->Connect(std::unique_ptr<JSBindingsSessionDelegate>(
69-
new JSBindingsSessionDelegate(env, this)), false);
70+
session_ = inspector->Connect(std::make_unique<JSBindingsSessionDelegate>(
71+
env, this), false);
7072
}
7173

7274
void OnMessage(Local<Value> value) {

src/node_file.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ int FileHandle::ReadStart() {
344344
.ToLocal(&wrap_obj)) {
345345
return UV_EBUSY;
346346
}
347-
read_wrap.reset(new FileHandleReadWrap(this, wrap_obj));
347+
read_wrap = std::make_unique<FileHandleReadWrap>(this, wrap_obj);
348348
}
349349
}
350350
int64_t recommended_read = 65536;
@@ -1288,8 +1288,8 @@ int MKDirpAsync(uv_loop_t* loop,
12881288
FSReqBase* req_wrap = FSReqBase::from_req(req);
12891289
// on the first iteration of algorithm, stash state information.
12901290
if (req_wrap->continuation_data == nullptr) {
1291-
req_wrap->continuation_data = std::unique_ptr<FSContinuationData>{
1292-
new FSContinuationData(req, mode, cb)};
1291+
req_wrap->continuation_data =
1292+
std::make_unique<FSContinuationData>(req, mode, cb);
12931293
req_wrap->continuation_data->PushPath(std::move(path));
12941294
}
12951295

src/node_platform.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "debug_utils.h"
66
#include "util.h"
77
#include <algorithm>
8+
#include <memory>
89

910
namespace node {
1011

@@ -172,8 +173,8 @@ WorkerThreadsTaskRunner::WorkerThreadsTaskRunner(int thread_pool_size) {
172173
Mutex::ScopedLock lock(platform_workers_mutex);
173174
int pending_platform_workers = thread_pool_size;
174175

175-
delayed_task_scheduler_.reset(
176-
new DelayedTaskScheduler(&pending_worker_tasks_));
176+
delayed_task_scheduler_ = std::make_unique<DelayedTaskScheduler>(
177+
&pending_worker_tasks_);
177178
threads_.push_back(delayed_task_scheduler_->Start());
178179

179180
for (int i = 0; i < thread_pool_size; i++) {

src/node_v8_platform-inl.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
55

6+
#include <memory>
7+
68
#include "env-inl.h"
79
#include "node.h"
810
#include "node_metadata.h"
@@ -79,11 +81,12 @@ class NodeTraceStateObserver
7981
struct V8Platform {
8082
#if NODE_USE_V8_PLATFORM
8183
inline void Initialize(int thread_pool_size) {
82-
tracing_agent_.reset(new tracing::Agent());
84+
tracing_agent_ = std::make_unique<tracing::Agent>();
8385
node::tracing::TraceEventHelper::SetAgent(tracing_agent_.get());
8486
node::tracing::TracingController* controller =
8587
tracing_agent_->GetTracingController();
86-
trace_state_observer_.reset(new NodeTraceStateObserver(controller));
88+
trace_state_observer_ =
89+
std::make_unique<NodeTraceStateObserver>(controller);
8790
controller->AddTraceStateObserver(trace_state_observer_.get());
8891
tracing_file_writer_ = tracing_agent_->DefaultHandle();
8992
// Only start the tracing agent if we enabled any tracing categories.

src/node_worker.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "inspector/worker_inspector.h" // ParentInspectorHandle
1111
#endif
1212

13+
#include <memory>
1314
#include <string>
1415
#include <vector>
1516

@@ -77,7 +78,7 @@ Worker::Worker(Environment* env,
7778
return;
7879
}
7980

80-
child_port_data_.reset(new MessagePortData(nullptr));
81+
child_port_data_ = std::make_unique<MessagePortData>(nullptr);
8182
MessagePort::Entangle(parent_port_, child_port_data_.get());
8283

8384
object()->Set(env->context(),

src/tracing/node_trace_buffer.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "tracing/node_trace_buffer.h"
2+
3+
#include <memory>
24
#include "util-inl.h"
35

46
namespace node {
@@ -19,7 +21,7 @@ TraceObject* InternalTraceBuffer::AddTraceEvent(uint64_t* handle) {
1921
if (chunk) {
2022
chunk->Reset(current_chunk_seq_++);
2123
} else {
22-
chunk.reset(new TraceBufferChunk(current_chunk_seq_++));
24+
chunk = std::make_unique<TraceBufferChunk>(current_chunk_seq_++);
2325
}
2426
}
2527
auto& chunk = chunks_[total_chunks_ - 1];

test/cctest/node_test_fixture.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define TEST_CCTEST_NODE_TEST_FIXTURE_H_
33

44
#include <cstdlib>
5+
#include <memory>
56
#include "gtest/gtest.h"
67
#include "node.h"
78
#include "node_platform.h"
@@ -77,7 +78,7 @@ class NodeTestFixture : public ::testing::Test {
7778
node::Init(&argc, &argv0, &exec_argc, &exec_argv);
7879
}
7980

80-
tracing_agent.reset(new node::tracing::Agent());
81+
tracing_agent = std::make_unique<node::tracing::Agent>();
8182
node::tracing::TraceEventHelper::SetAgent(tracing_agent.get());
8283
CHECK_EQ(0, uv_loop_init(&current_loop));
8384
platform.reset(static_cast<node::NodePlatform*>(

test/cctest/test_inspector_socket_server.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "gtest/gtest.h"
55

66
#include <algorithm>
7+
#include <memory>
78
#include <sstream>
89

910
static uv_loop_t loop;
@@ -356,8 +357,8 @@ ServerHolder::ServerHolder(bool has_targets, uv_loop_t* loop,
356357
targets = { MAIN_TARGET_ID };
357358
std::unique_ptr<TestSocketServerDelegate> delegate(
358359
new TestSocketServerDelegate(this, targets));
359-
server_.reset(
360-
new InspectorSocketServer(std::move(delegate), loop, host, port, out));
360+
server_ = std::make_unique<InspectorSocketServer>(
361+
std::move(delegate), loop, host, port, out);
361362
}
362363

363364
static void TestHttpRequest(int port, const std::string& path,

0 commit comments

Comments
 (0)