src: apply clang-tidy rule modernize-make-unique · nodejs/node@c51cc9e (original) (raw)

12 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
30 30
31 31 #include <cerrno>
32 32 #include <cstring>
33 +#include <memory>
33 34 #include <vector>
34 35 #include <unordered_set>
35 36
@@ -663,7 +664,7 @@ class QueryWrap : public AsyncWrap {
663 664 memcpy(buf_copy, answer_buf, answer_len);
664 665 }
665 666
666 - wrap->response_data_.reset(new ResponseData());
667 + wrap->response_data_ = std::make_unique<ResponseData>();
667 668 ResponseData* data = wrap->response_data_.get();
668 669 data->status = status;
669 670 data->is_host = false;
@@ -683,7 +684,7 @@ class QueryWrap : public AsyncWrap {
683 684 cares_wrap_hostent_cpy(host_copy, host);
684 685 }
685 686
686 - wrap->response_data_.reset(new ResponseData());
687 + wrap->response_data_ = std::make_unique<ResponseData>();
687 688 ResponseData* data = wrap->response_data_.get();
688 689 data->status = status;
689 690 data->host.reset(host_copy);
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@
19 19 #include <algorithm>
20 20 #include <atomic>
21 21 #include <cstdio>
22 +#include <memory>
22 23
23 24 namespace node {
24 25
@@ -217,8 +218,7 @@ Environment::Environment(IsolateData* isolate_data,
217 218
218 219 #if HAVE_INSPECTOR
219 220 // We can only create the inspector agent after having cloned the options.
220 - inspector_agent_ =
221 - std::unique_ptrinspector::Agent(new inspector::Agent(this));
221 + inspector_agent_ = std::make_uniqueinspector::Agent(this);
222 222 #endif
223 223
224 224 AssignToContext(context, ContextInfo(""));
@@ -238,7 +238,8 @@ Environment::Environment(IsolateData* isolate_data,
238 238 },
239 239 this);
240 240
241 - performance_state_.reset(new performance::performance_state(isolate()));
241 + performance_state_ =
242 + std::make_uniqueperformance::performance\_state(isolate());
242 243 performance_state_->Mark(
243 244 performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
244 245 performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_NODE_START,
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
7 7 #include <unicode/unistr.h>
8 8
9 9 #include <functional>
10 +#include <memory>
10 11
11 12 namespace node {
12 13 namespace inspector {
@@ -114,8 +115,7 @@ class AnotherThreadObjectReference {
114 115
115 116 ~AnotherThreadObjectReference() {
116 117 // Disappearing thread may cause a memory leak
117 - thread_->Post(
118 - std::unique_ptr(new DeleteRequest(object_id_)));
118 + thread_->Post(std::make_unique(object_id_));
119 119 }
120 120
121 121 template
@@ -151,8 +151,7 @@ class MainThreadSessionState {
151 151
152 152 static std::unique_ptr Create(
153 153 MainThreadInterface* thread, bool prevent_shutdown) {
154 -return std::unique_ptr(
155 -new MainThreadSessionState(thread, prevent_shutdown));
154 +return std::make_unique(thread, prevent_shutdown);
156 155 }
157 156
158 157 void Connect(std::unique_ptr delegate) {
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
1 1 #include "worker_inspector.h"
2 -
3 2 #include "main_thread_interface.h"
4 3
4 +#include <memory>
5 +
5 6 namespace node {
6 7 namespace inspector {
7 8 namespace {
@@ -88,8 +89,7 @@ void WorkerManager::WorkerStarted(int session_id,
88 89 std::unique_ptr
89 90 WorkerManager::NewParentHandle(int thread_id, const std::string& url) {
90 91 bool wait = !delegates_waiting_on_start_.empty();
91 -return std::unique_ptr(
92 -new ParentInspectorHandle(thread_id, url, thread_, wait));
92 +return std::make_unique(thread_id, url, thread_, wait);
93 93 }
94 94
95 95 void WorkerManager::RemoveAttachDelegate(int id) {
@@ -106,8 +106,7 @@ std::unique_ptr WorkerManager::SetAutoAttach(
106 106 // Waiting is only reported when a worker is started, same as browser
107 107 Report(delegate, worker.second, false);
108 108 }
109 -return std::unique_ptr(
110 -new WorkerManagerEventHandle(shared_from_this(), id));
109 +return std::make_unique(shared_from_this(), id);
111 110 }
112 111
113 112 void WorkerManager::SetWaitOnStartForDelegate(int id, bool wait) {
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@
4 4 #include "v8.h"
5 5 #include "v8-inspector.h"
6 6
7 +#include <memory>
8 +
7 9 namespace node {
8 10 namespace inspector {
9 11 namespace {
@@ -65,8 +67,8 @@ class JSBindingsConnection : public AsyncWrap {
65 67 : AsyncWrap(env, wrap, PROVIDER_INSPECTORJSBINDING),
66 68 callback_(env->isolate(), callback) {
67 69 Agent* inspector = env->inspector_agent();
68 - session_ = inspector->Connect(std::unique_ptr(
69 -new JSBindingsSessionDelegate(env, this)), false);
70 + session_ = inspector->Connect(std::make_unique(
71 + env, this), false);
70 72 }
71 73
72 74 void OnMessage(Local value) {
Original file line number Diff line number Diff line change
@@ -344,7 +344,7 @@ int FileHandle::ReadStart() {
344 344 .ToLocal(&wrap_obj)) {
345 345 return UV_EBUSY;
346 346 }
347 - read_wrap.reset(new FileHandleReadWrap(this, wrap_obj));
347 + read_wrap = std::make_unique<FileHandleReadWrap>(this, wrap_obj);
348 348 }
349 349 }
350 350 int64_t recommended_read = 65536;
@@ -1288,8 +1288,8 @@ int MKDirpAsync(uv_loop_t* loop,
1288 1288 FSReqBase* req_wrap = FSReqBase::from_req(req);
1289 1289 // on the first iteration of algorithm, stash state information.
1290 1290 if (req_wrap->continuation_data == nullptr) {
1291 - req_wrap->continuation_data = std::unique_ptr{
1292 -new FSContinuationData(req, mode, cb)};
1291 + req_wrap->continuation_data =
1292 + std::make_unique<FSContinuationData>(req, mode, cb);
1293 1293 req_wrap->continuation_data->PushPath(std::move(path));
1294 1294 }
1295 1295
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
5 5 #include "debug_utils.h"
6 6 #include "util.h"
7 7 #include <algorithm>
8 +#include <memory>
8 9
9 10 namespace node {
10 11
@@ -172,8 +173,8 @@ WorkerThreadsTaskRunner::WorkerThreadsTaskRunner(int thread_pool_size) {
172 173 Mutex::ScopedLock lock(platform_workers_mutex);
173 174 int pending_platform_workers = thread_pool_size;
174 175
175 - delayed_task_scheduler_.reset(
176 -new DelayedTaskScheduler(&pending_worker_tasks_));
176 + delayed_task_scheduler_ = std::make_unique(
177 + &pending_worker_tasks_);
177 178 threads_.push_back(delayed_task_scheduler_->Start());
178 179
179 180 for (int i = 0; i < thread_pool_size; i++) {
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@
3 3
4 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5 5
6 +#include <memory>
7 +
6 8 #include "env-inl.h"
7 9 #include "node.h"
8 10 #include "node_metadata.h"
@@ -79,11 +81,12 @@ class NodeTraceStateObserver
79 81 struct V8Platform {
80 82 #if NODE_USE_V8_PLATFORM
81 83 inline void Initialize(int thread_pool_size) {
82 - tracing_agent_.reset(new tracing::Agent());
84 + tracing_agent_ = std::make_uniquetracing::Agent\();
83 85 node::tracing::TraceEventHelper::SetAgent(tracing_agent_.get());
84 86 node::tracing::TracingController* controller =
85 87 tracing_agent_->GetTracingController();
86 - trace_state_observer_.reset(new NodeTraceStateObserver(controller));
88 + trace_state_observer_ =
89 + std::make_unique(controller);
87 90 controller->AddTraceStateObserver(trace_state_observer_.get());
88 91 tracing_file_writer_ = tracing_agent_->DefaultHandle();
89 92 // Only start the tracing agent if we enabled any tracing categories.
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
10 10 #include "inspector/worker_inspector.h" // ParentInspectorHandle
11 11 #endif
12 12
13 +#include <memory>
13 14 #include <string>
14 15 #include <vector>
15 16
@@ -77,7 +78,7 @@ Worker::Worker(Environment* env,
77 78 return;
78 79 }
79 80
80 - child_port_data_.reset(new MessagePortData(nullptr));
81 + child_port_data_ = std::make_unique<MessagePortData>(nullptr);
81 82 MessagePort::Entangle(parent_port_, child_port_data_.get());
82 83
83 84 object()->Set(env->context(),
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
1 1 #include "tracing/node_trace_buffer.h"
2 +
3 +#include <memory>
2 4 #include "util-inl.h"
3 5
4 6 namespace node {
@@ -19,7 +21,7 @@ TraceObject* InternalTraceBuffer::AddTraceEvent(uint64_t* handle) {
19 21 if (chunk) {
20 22 chunk->Reset(current_chunk_seq_++);
21 23 } else {
22 - chunk.reset(new TraceBufferChunk(current_chunk_seq_++));
24 + chunk = std::make_unique<TraceBufferChunk>(current_chunk_seq_++);
23 25 }
24 26 }
25 27 auto& chunk = chunks_[total_chunks_ - 1];
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
2 2 #define TEST_CCTEST_NODE_TEST_FIXTURE_H_
3 3
4 4 #include <cstdlib>
5 +#include <memory>
5 6 #include "gtest/gtest.h"
6 7 #include "node.h"
7 8 #include "node_platform.h"
@@ -77,7 +78,7 @@ class NodeTestFixture : public ::testing::Test {
77 78 node::Init(&argc, &argv0, &exec_argc, &exec_argv);
78 79 }
79 80
80 - tracing_agent.reset(new node::tracing::Agent());
81 + tracing_agent = std::make_uniquenode::tracing::Agent\();
81 82 node::tracing::TraceEventHelper::SetAgent(tracing_agent.get());
82 83 CHECK_EQ(0, uv_loop_init(&current_loop));
83 84 platform.reset(static_castnode::NodePlatform\*(
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
4 4 #include "gtest/gtest.h"
5 5
6 6 #include <algorithm>
7 +#include <memory>
7 8 #include <sstream>
8 9
9 10 static uv_loop_t loop;
@@ -356,8 +357,8 @@ ServerHolder::ServerHolder(bool has_targets, uv_loop_t* loop,
356 357 targets = { MAIN_TARGET_ID };
357 358 std::unique_ptr delegate(
358 359 new TestSocketServerDelegate(this, targets));
359 - server_.reset(
360 -new InspectorSocketServer(std::move(delegate), loop, host, port, out));
360 + server_ = std::make_unique(
361 +std::move(delegate), loop, host, port, out);
361 362 }
362 363
363 364 static void TestHttpRequest(int port, const std::string& path,