Skip to content

Commit

Permalink
src: apply clang-tidy various improvement
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
gengjiawen authored and refack committed Mar 10, 2019
1 parent 7891339 commit 6e81a95
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
22 changes: 12 additions & 10 deletions src/node_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "node_errors.h"
#include "node_internals.h"

#include <memory>

struct node_napi_env__ : public napi_env__ {
explicit node_napi_env__(v8::Local<v8::Context> context):
napi_env__(context) {
Expand Down Expand Up @@ -220,9 +222,9 @@ class ThreadSafeFunction : public node::AsyncResource {

if (uv_async_init(loop, &async, AsyncCb) == 0) {
if (max_queue_size > 0) {
cond.reset(new node::ConditionVariable);
cond = std::make_unique<node::ConditionVariable>();
}
if ((max_queue_size == 0 || cond.get() != nullptr) &&
if ((max_queue_size == 0 || cond) &&
uv_idle_init(loop, &idle) == 0) {
return napi_ok;
}
Expand Down Expand Up @@ -809,15 +811,15 @@ namespace uvimpl {

static napi_status ConvertUVErrorCode(int code) {
switch (code) {
case 0:
return napi_ok;
case UV_EINVAL:
return napi_invalid_arg;
case UV_ECANCELED:
return napi_cancelled;
case 0:
return napi_ok;
case UV_EINVAL:
return napi_invalid_arg;
case UV_ECANCELED:
return napi_cancelled;
default:
return napi_generic_failure;
}

return napi_generic_failure;
}

// Wrapper around uv_work_t which calls user-provided callbacks.
Expand Down
4 changes: 1 addition & 3 deletions src/node_crypto_bio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,7 @@ char* NodeBIO::PeekWritable(size_t* size) {
TryAllocateForWrite(*size);

size_t available = write_head_->len_ - write_head_->write_pos_;
if (*size != 0 && available > *size)
available = *size;
else
if (*size == 0 || available <= *size)
*size = available;

return write_head_->data_ + write_head_->write_pos_;
Expand Down
6 changes: 3 additions & 3 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
const int64_t pos = GET_OFFSET(args[4]);

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

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

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

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

Local<Value> error;
MaybeLocal<Value> rc =
Expand Down

0 comments on commit 6e81a95

Please sign in to comment.