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: https://github.com/nodejs/node/pull/26470
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
gengjiawen 2019-03-06 09:15:22 -05:00 committed by Refael Ackermann
parent 78913393fa
commit 6e81a959d0
3 changed files with 16 additions and 16 deletions

View File

@ -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) {
@ -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;
}
@ -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.

View File

@ -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_;

View File

@ -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)
@ -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)
@ -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 =