From 3022e0d6145c405dbd6395e3a68754b8b72f5e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 19 Jul 2020 23:14:56 +0200 Subject: [PATCH] src: prefer C++ empty() in boolean expressions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/34432 Reviewed-By: Richard Lau Reviewed-By: Michaƫl Zasso Reviewed-By: Jiawen Geng Reviewed-By: Ben Noordhuis Reviewed-By: Gus Caplan Reviewed-By: David Carlier Reviewed-By: James M Snell Reviewed-By: Trivikram Kamat Reviewed-By: Franziska Hinkelmann --- src/inspector_agent.cc | 2 +- src/inspector_js_api.cc | 2 +- src/node_file-inl.h | 2 +- src/node_http2.cc | 8 ++++---- src/node_url.cc | 8 ++++---- src/node_worker.cc | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index f8625ae866fe5f..e6ab76abf56168 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -445,7 +445,7 @@ bool IsFilePath(const std::string& path) { } #else bool IsFilePath(const std::string& path) { - return path.length() && path[0] == '/'; + return !path.empty() && path[0] == '/'; } #endif // __POSIX__ diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index c318f78646634d..8616575e066121 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -302,7 +302,7 @@ void WaitForDebugger(const FunctionCallbackInfo& args) { void Url(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); std::string url = env->inspector_agent()->GetWsUrl(); - if (url.length() == 0) { + if (url.empty()) { return; } args.GetReturnValue().Set(OneByteString(env->isolate(), url.c_str())); diff --git a/src/node_file-inl.h b/src/node_file-inl.h index 2ad8c73f05e490..0188261b7dcbb4 100644 --- a/src/node_file-inl.h +++ b/src/node_file-inl.h @@ -28,7 +28,7 @@ void FSContinuationData::MaybeSetFirstPath(const std::string& path) { } std::string FSContinuationData::PopPath() { - CHECK_GT(paths_.size(), 0); + CHECK(!paths_.empty()); std::string path = std::move(paths_.back()); paths_.pop_back(); return path; diff --git a/src/node_http2.cc b/src/node_http2.cc index a7cdb77b8c07a8..5aa817a1ac8442 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -1510,7 +1510,7 @@ void Http2Session::ClearOutgoing(int status) { set_sending(false); - if (outgoing_buffers_.size() > 0) { + if (!outgoing_buffers_.empty()) { outgoing_storage_.clear(); outgoing_length_ = 0; @@ -1529,7 +1529,7 @@ void Http2Session::ClearOutgoing(int status) { // Now that we've finished sending queued data, if there are any pending // RstStreams we should try sending again and then flush them one by one. - if (pending_rst_streams_.size() > 0) { + if (!pending_rst_streams_.empty()) { std::vector current_pending_rst_streams; pending_rst_streams_.swap(current_pending_rst_streams); @@ -1588,8 +1588,8 @@ uint8_t Http2Session::SendPendingData() { ssize_t src_length; const uint8_t* src; - CHECK_EQ(outgoing_buffers_.size(), 0); - CHECK_EQ(outgoing_storage_.size(), 0); + CHECK(outgoing_buffers_.empty()); + CHECK(outgoing_storage_.empty()); // Part One: Gather data from nghttp2 diff --git a/src/node_url.cc b/src/node_url.cc index 4f0d5f284b14dd..b157c2ded1b5ae 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -1169,7 +1169,7 @@ bool ParseHost(const std::string& input, std::string* output, bool is_special, bool unicode = false) { - if (input.length() == 0) { + if (input.empty()) { output->clear(); return true; } @@ -2036,7 +2036,7 @@ void URL::Parse(const char* input, (ch == kEOL || ch == '?' || ch == '#')) { - while (url->path.size() > 1 && url->path[0].length() == 0) { + while (url->path.size() > 1 && url->path[0].empty()) { url->path.erase(url->path.begin()); } } @@ -2059,9 +2059,9 @@ void URL::Parse(const char* input, state = kFragment; break; default: - if (url->path.size() == 0) + if (url->path.empty()) url->path.emplace_back(""); - if (url->path.size() > 0 && ch != kEOL) + else if (ch != kEOL) AppendOrEscape(&url->path[0], ch, C0_CONTROL_ENCODE_SET); } break; diff --git a/src/node_worker.cc b/src/node_worker.cc index 0b2fb39c9fe2d1..a017e475918e1b 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -501,7 +501,7 @@ void Worker::New(const FunctionCallbackInfo& args) { per_isolate_opts.get(), kAllowedInEnvironment, &errors); - if (errors.size() > 0 && args[1]->IsObject()) { + if (!errors.empty() && args[1]->IsObject()) { // Only fail for explicitly provided env, this protects from failures // when NODE_OPTIONS from parent's env is used (which is the default). Local error;