src: apply clang-tidy rule modernize-make-unique

PR-URL: https://github.com/nodejs/node/pull/26493
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
gengjiawen 2019-03-07 21:46:54 +08:00 committed by Ruben Bridgewater
parent 90fdf1b0d3
commit 575e086b66
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
12 changed files with 39 additions and 28 deletions

View File

@ -30,6 +30,7 @@
#include <cerrno> #include <cerrno>
#include <cstring> #include <cstring>
#include <memory>
#include <vector> #include <vector>
#include <unordered_set> #include <unordered_set>
@ -663,7 +664,7 @@ class QueryWrap : public AsyncWrap {
memcpy(buf_copy, answer_buf, answer_len); memcpy(buf_copy, answer_buf, answer_len);
} }
wrap->response_data_.reset(new ResponseData()); wrap->response_data_ = std::make_unique<ResponseData>();
ResponseData* data = wrap->response_data_.get(); ResponseData* data = wrap->response_data_.get();
data->status = status; data->status = status;
data->is_host = false; data->is_host = false;
@ -683,7 +684,7 @@ class QueryWrap : public AsyncWrap {
cares_wrap_hostent_cpy(host_copy, host); cares_wrap_hostent_cpy(host_copy, host);
} }
wrap->response_data_.reset(new ResponseData()); wrap->response_data_ = std::make_unique<ResponseData>();
ResponseData* data = wrap->response_data_.get(); ResponseData* data = wrap->response_data_.get();
data->status = status; data->status = status;
data->host.reset(host_copy); data->host.reset(host_copy);

View File

@ -19,6 +19,7 @@
#include <algorithm> #include <algorithm>
#include <atomic> #include <atomic>
#include <cstdio> #include <cstdio>
#include <memory>
namespace node { namespace node {
@ -217,8 +218,7 @@ Environment::Environment(IsolateData* isolate_data,
#if HAVE_INSPECTOR #if HAVE_INSPECTOR
// We can only create the inspector agent after having cloned the options. // We can only create the inspector agent after having cloned the options.
inspector_agent_ = inspector_agent_ = std::make_unique<inspector::Agent>(this);
std::unique_ptr<inspector::Agent>(new inspector::Agent(this));
#endif #endif
AssignToContext(context, ContextInfo("")); AssignToContext(context, ContextInfo(""));
@ -238,7 +238,8 @@ Environment::Environment(IsolateData* isolate_data,
}, },
this); this);
performance_state_.reset(new performance::performance_state(isolate())); performance_state_ =
std::make_unique<performance::performance_state>(isolate());
performance_state_->Mark( performance_state_->Mark(
performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT); performance::NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_NODE_START, performance_state_->Mark(performance::NODE_PERFORMANCE_MILESTONE_NODE_START,

View File

@ -7,6 +7,7 @@
#include <unicode/unistr.h> #include <unicode/unistr.h>
#include <functional> #include <functional>
#include <memory>
namespace node { namespace node {
namespace inspector { namespace inspector {
@ -114,8 +115,7 @@ class AnotherThreadObjectReference {
~AnotherThreadObjectReference() { ~AnotherThreadObjectReference() {
// Disappearing thread may cause a memory leak // Disappearing thread may cause a memory leak
thread_->Post( thread_->Post(std::make_unique<DeleteRequest>(object_id_));
std::unique_ptr<DeleteRequest>(new DeleteRequest(object_id_)));
} }
template <typename Fn> template <typename Fn>
@ -151,8 +151,7 @@ class MainThreadSessionState {
static std::unique_ptr<MainThreadSessionState> Create( static std::unique_ptr<MainThreadSessionState> Create(
MainThreadInterface* thread, bool prevent_shutdown) { MainThreadInterface* thread, bool prevent_shutdown) {
return std::unique_ptr<MainThreadSessionState>( return std::make_unique<MainThreadSessionState>(thread, prevent_shutdown);
new MainThreadSessionState(thread, prevent_shutdown));
} }
void Connect(std::unique_ptr<InspectorSessionDelegate> delegate) { void Connect(std::unique_ptr<InspectorSessionDelegate> delegate) {

View File

@ -1,7 +1,8 @@
#include "worker_inspector.h" #include "worker_inspector.h"
#include "main_thread_interface.h" #include "main_thread_interface.h"
#include <memory>
namespace node { namespace node {
namespace inspector { namespace inspector {
namespace { namespace {
@ -88,8 +89,7 @@ void WorkerManager::WorkerStarted(int session_id,
std::unique_ptr<ParentInspectorHandle> std::unique_ptr<ParentInspectorHandle>
WorkerManager::NewParentHandle(int thread_id, const std::string& url) { WorkerManager::NewParentHandle(int thread_id, const std::string& url) {
bool wait = !delegates_waiting_on_start_.empty(); bool wait = !delegates_waiting_on_start_.empty();
return std::unique_ptr<ParentInspectorHandle>( return std::make_unique<ParentInspectorHandle>(thread_id, url, thread_, wait);
new ParentInspectorHandle(thread_id, url, thread_, wait));
} }
void WorkerManager::RemoveAttachDelegate(int id) { void WorkerManager::RemoveAttachDelegate(int id) {
@ -106,8 +106,7 @@ std::unique_ptr<WorkerManagerEventHandle> WorkerManager::SetAutoAttach(
// Waiting is only reported when a worker is started, same as browser // Waiting is only reported when a worker is started, same as browser
Report(delegate, worker.second, false); Report(delegate, worker.second, false);
} }
return std::unique_ptr<WorkerManagerEventHandle>( return std::make_unique<WorkerManagerEventHandle>(shared_from_this(), id);
new WorkerManagerEventHandle(shared_from_this(), id));
} }
void WorkerManager::SetWaitOnStartForDelegate(int id, bool wait) { void WorkerManager::SetWaitOnStartForDelegate(int id, bool wait) {

View File

@ -4,6 +4,8 @@
#include "v8.h" #include "v8.h"
#include "v8-inspector.h" #include "v8-inspector.h"
#include <memory>
namespace node { namespace node {
namespace inspector { namespace inspector {
namespace { namespace {
@ -65,8 +67,8 @@ class JSBindingsConnection : public AsyncWrap {
: AsyncWrap(env, wrap, PROVIDER_INSPECTORJSBINDING), : AsyncWrap(env, wrap, PROVIDER_INSPECTORJSBINDING),
callback_(env->isolate(), callback) { callback_(env->isolate(), callback) {
Agent* inspector = env->inspector_agent(); Agent* inspector = env->inspector_agent();
session_ = inspector->Connect(std::unique_ptr<JSBindingsSessionDelegate>( session_ = inspector->Connect(std::make_unique<JSBindingsSessionDelegate>(
new JSBindingsSessionDelegate(env, this)), false); env, this), false);
} }
void OnMessage(Local<Value> value) { void OnMessage(Local<Value> value) {

View File

@ -341,7 +341,7 @@ int FileHandle::ReadStart() {
.ToLocal(&wrap_obj)) { .ToLocal(&wrap_obj)) {
return UV_EBUSY; return UV_EBUSY;
} }
read_wrap.reset(new FileHandleReadWrap(this, wrap_obj)); read_wrap = std::make_unique<FileHandleReadWrap>(this, wrap_obj);
} }
} }
int64_t recommended_read = 65536; int64_t recommended_read = 65536;
@ -1285,8 +1285,8 @@ int MKDirpAsync(uv_loop_t* loop,
FSReqBase* req_wrap = FSReqBase::from_req(req); FSReqBase* req_wrap = FSReqBase::from_req(req);
// on the first iteration of algorithm, stash state information. // on the first iteration of algorithm, stash state information.
if (req_wrap->continuation_data == nullptr) { if (req_wrap->continuation_data == nullptr) {
req_wrap->continuation_data = std::unique_ptr<FSContinuationData>{ req_wrap->continuation_data =
new FSContinuationData(req, mode, cb)}; std::make_unique<FSContinuationData>(req, mode, cb);
req_wrap->continuation_data->PushPath(std::move(path)); req_wrap->continuation_data->PushPath(std::move(path));
} }

View File

@ -5,6 +5,7 @@
#include "debug_utils.h" #include "debug_utils.h"
#include "util.h" #include "util.h"
#include <algorithm> #include <algorithm>
#include <memory>
namespace node { namespace node {
@ -172,8 +173,8 @@ WorkerThreadsTaskRunner::WorkerThreadsTaskRunner(int thread_pool_size) {
Mutex::ScopedLock lock(platform_workers_mutex); Mutex::ScopedLock lock(platform_workers_mutex);
int pending_platform_workers = thread_pool_size; int pending_platform_workers = thread_pool_size;
delayed_task_scheduler_.reset( delayed_task_scheduler_ = std::make_unique<DelayedTaskScheduler>(
new DelayedTaskScheduler(&pending_worker_tasks_)); &pending_worker_tasks_);
threads_.push_back(delayed_task_scheduler_->Start()); threads_.push_back(delayed_task_scheduler_->Start());
for (int i = 0; i < thread_pool_size; i++) { for (int i = 0; i < thread_pool_size; i++) {

View File

@ -3,6 +3,8 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include <memory>
#include "env-inl.h" #include "env-inl.h"
#include "node.h" #include "node.h"
#include "node_metadata.h" #include "node_metadata.h"
@ -79,11 +81,12 @@ class NodeTraceStateObserver
struct V8Platform { struct V8Platform {
#if NODE_USE_V8_PLATFORM #if NODE_USE_V8_PLATFORM
inline void Initialize(int thread_pool_size) { inline void Initialize(int thread_pool_size) {
tracing_agent_.reset(new tracing::Agent()); tracing_agent_ = std::make_unique<tracing::Agent>();
node::tracing::TraceEventHelper::SetAgent(tracing_agent_.get()); node::tracing::TraceEventHelper::SetAgent(tracing_agent_.get());
node::tracing::TracingController* controller = node::tracing::TracingController* controller =
tracing_agent_->GetTracingController(); tracing_agent_->GetTracingController();
trace_state_observer_.reset(new NodeTraceStateObserver(controller)); trace_state_observer_ =
std::make_unique<NodeTraceStateObserver>(controller);
controller->AddTraceStateObserver(trace_state_observer_.get()); controller->AddTraceStateObserver(trace_state_observer_.get());
tracing_file_writer_ = tracing_agent_->DefaultHandle(); tracing_file_writer_ = tracing_agent_->DefaultHandle();
// Only start the tracing agent if we enabled any tracing categories. // Only start the tracing agent if we enabled any tracing categories.

View File

@ -10,6 +10,7 @@
#include "inspector/worker_inspector.h" // ParentInspectorHandle #include "inspector/worker_inspector.h" // ParentInspectorHandle
#endif #endif
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -117,7 +118,7 @@ Worker::Worker(Environment* env,
return; return;
} }
child_port_data_.reset(new MessagePortData(nullptr)); child_port_data_ = std::make_unique<MessagePortData>(nullptr);
MessagePort::Entangle(parent_port_, child_port_data_.get()); MessagePort::Entangle(parent_port_, child_port_data_.get());
object()->Set(env->context(), object()->Set(env->context(),

View File

@ -1,4 +1,6 @@
#include "tracing/node_trace_buffer.h" #include "tracing/node_trace_buffer.h"
#include <memory>
#include "util-inl.h" #include "util-inl.h"
namespace node { namespace node {
@ -19,7 +21,7 @@ TraceObject* InternalTraceBuffer::AddTraceEvent(uint64_t* handle) {
if (chunk) { if (chunk) {
chunk->Reset(current_chunk_seq_++); chunk->Reset(current_chunk_seq_++);
} else { } else {
chunk.reset(new TraceBufferChunk(current_chunk_seq_++)); chunk = std::make_unique<TraceBufferChunk>(current_chunk_seq_++);
} }
} }
auto& chunk = chunks_[total_chunks_ - 1]; auto& chunk = chunks_[total_chunks_ - 1];

View File

@ -2,6 +2,7 @@
#define TEST_CCTEST_NODE_TEST_FIXTURE_H_ #define TEST_CCTEST_NODE_TEST_FIXTURE_H_
#include <cstdlib> #include <cstdlib>
#include <memory>
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "node.h" #include "node.h"
#include "node_platform.h" #include "node_platform.h"
@ -77,7 +78,7 @@ class NodeTestFixture : public ::testing::Test {
node::Init(&argc, &argv0, &exec_argc, &exec_argv); node::Init(&argc, &argv0, &exec_argc, &exec_argv);
} }
tracing_agent.reset(new node::tracing::Agent()); tracing_agent = std::make_unique<node::tracing::Agent>();
node::tracing::TraceEventHelper::SetAgent(tracing_agent.get()); node::tracing::TraceEventHelper::SetAgent(tracing_agent.get());
CHECK_EQ(0, uv_loop_init(&current_loop)); CHECK_EQ(0, uv_loop_init(&current_loop));
platform.reset(static_cast<node::NodePlatform*>( platform.reset(static_cast<node::NodePlatform*>(

View File

@ -4,6 +4,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include <algorithm> #include <algorithm>
#include <memory>
#include <sstream> #include <sstream>
static uv_loop_t loop; static uv_loop_t loop;
@ -356,8 +357,8 @@ ServerHolder::ServerHolder(bool has_targets, uv_loop_t* loop,
targets = { MAIN_TARGET_ID }; targets = { MAIN_TARGET_ID };
std::unique_ptr<TestSocketServerDelegate> delegate( std::unique_ptr<TestSocketServerDelegate> delegate(
new TestSocketServerDelegate(this, targets)); new TestSocketServerDelegate(this, targets));
server_.reset( server_ = std::make_unique<InspectorSocketServer>(
new InspectorSocketServer(std::move(delegate), loop, host, port, out)); std::move(delegate), loop, host, port, out);
} }
static void TestHttpRequest(int port, const std::string& path, static void TestHttpRequest(int port, const std::string& path,