Skip to content

Commit a99fb54

Browse files
gengjiawenBridgeAR
authored andcommitted
src: apply clang-tidy various improvement
* rewrite to default label in method ConvertUVErrorCode * improve if condition in method PeekWritable * remove redundant cast in node_file.cc PR-URL: #26470 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent d590a45 commit a99fb54

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

Diff for: src/node_api.cc

+12-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "node_errors.h"
88
#include "node_internals.h"
99

10+
#include <memory>
11+
1012
struct node_napi_env__ : public napi_env__ {
1113
explicit node_napi_env__(v8::Local<v8::Context> context):
1214
napi_env__(context) {
@@ -220,9 +222,9 @@ class ThreadSafeFunction : public node::AsyncResource {
220222

221223
if (uv_async_init(loop, &async, AsyncCb) == 0) {
222224
if (max_queue_size > 0) {
223-
cond.reset(new node::ConditionVariable);
225+
cond = std::make_unique<node::ConditionVariable>();
224226
}
225-
if ((max_queue_size == 0 || cond.get() != nullptr) &&
227+
if ((max_queue_size == 0 || cond) &&
226228
uv_idle_init(loop, &idle) == 0) {
227229
return napi_ok;
228230
}
@@ -809,15 +811,15 @@ namespace uvimpl {
809811

810812
static napi_status ConvertUVErrorCode(int code) {
811813
switch (code) {
812-
case 0:
813-
return napi_ok;
814-
case UV_EINVAL:
815-
return napi_invalid_arg;
816-
case UV_ECANCELED:
817-
return napi_cancelled;
814+
case 0:
815+
return napi_ok;
816+
case UV_EINVAL:
817+
return napi_invalid_arg;
818+
case UV_ECANCELED:
819+
return napi_cancelled;
820+
default:
821+
return napi_generic_failure;
818822
}
819-
820-
return napi_generic_failure;
821823
}
822824

823825
// Wrapper around uv_work_t which calls user-provided callbacks.

Diff for: src/node_crypto_bio.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,7 @@ char* NodeBIO::PeekWritable(size_t* size) {
427427
TryAllocateForWrite(*size);
428428

429429
size_t available = write_head_->len_ - write_head_->write_pos_;
430-
if (*size != 0 && available > *size)
431-
available = *size;
432-
else
430+
if (*size == 0 || available <= *size)
433431
*size = available;
434432

435433
return write_head_->data_ + write_head_->write_pos_;

Diff for: src/node_file.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,7 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
16591659
const int64_t pos = GET_OFFSET(args[4]);
16601660

16611661
char* buf = buffer_data + off;
1662-
uv_buf_t uvbuf = uv_buf_init(const_cast<char*>(buf), len);
1662+
uv_buf_t uvbuf = uv_buf_init(buf, len);
16631663

16641664
FSReqBase* req_wrap_async = GetReqWrap(env, args[5]);
16651665
if (req_wrap_async != nullptr) { // write(fd, buffer, off, len, pos, req)
@@ -1858,7 +1858,7 @@ static void Read(const FunctionCallbackInfo<Value>& args) {
18581858
const int64_t pos = args[4].As<Integer>()->Value();
18591859

18601860
char* buf = buffer_data + off;
1861-
uv_buf_t uvbuf = uv_buf_init(const_cast<char*>(buf), len);
1861+
uv_buf_t uvbuf = uv_buf_init(buf, len);
18621862

18631863
FSReqBase* req_wrap_async = GetReqWrap(env, args[5]);
18641864
if (req_wrap_async != nullptr) { // read(fd, buffer, offset, len, pos, req)
@@ -2113,7 +2113,7 @@ static void Mkdtemp(const FunctionCallbackInfo<Value>& args) {
21132113
SyncCall(env, args[3], &req_wrap_sync, "mkdtemp",
21142114
uv_fs_mkdtemp, *tmpl);
21152115
FS_SYNC_TRACE_END(mkdtemp);
2116-
const char* path = static_cast<const char*>(req_wrap_sync.req.path);
2116+
const char* path = req_wrap_sync.req.path;
21172117

21182118
Local<Value> error;
21192119
MaybeLocal<Value> rc =

0 commit comments

Comments
 (0)