Skip to content

Commit 3022e0d

Browse files
tniessenBethGriggs
authored andcommitted
src: prefer C++ empty() in boolean expressions
PR-URL: #34432 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent b00f71b commit 3022e0d

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

src/inspector_agent.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ bool IsFilePath(const std::string& path) {
445445
}
446446
#else
447447
bool IsFilePath(const std::string& path) {
448-
return path.length() && path[0] == '/';
448+
return !path.empty() && path[0] == '/';
449449
}
450450
#endif // __POSIX__
451451

src/inspector_js_api.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void WaitForDebugger(const FunctionCallbackInfo<Value>& args) {
302302
void Url(const FunctionCallbackInfo<Value>& args) {
303303
Environment* env = Environment::GetCurrent(args);
304304
std::string url = env->inspector_agent()->GetWsUrl();
305-
if (url.length() == 0) {
305+
if (url.empty()) {
306306
return;
307307
}
308308
args.GetReturnValue().Set(OneByteString(env->isolate(), url.c_str()));

src/node_file-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void FSContinuationData::MaybeSetFirstPath(const std::string& path) {
2828
}
2929

3030
std::string FSContinuationData::PopPath() {
31-
CHECK_GT(paths_.size(), 0);
31+
CHECK(!paths_.empty());
3232
std::string path = std::move(paths_.back());
3333
paths_.pop_back();
3434
return path;

src/node_http2.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ void Http2Session::ClearOutgoing(int status) {
15101510

15111511
set_sending(false);
15121512

1513-
if (outgoing_buffers_.size() > 0) {
1513+
if (!outgoing_buffers_.empty()) {
15141514
outgoing_storage_.clear();
15151515
outgoing_length_ = 0;
15161516

@@ -1529,7 +1529,7 @@ void Http2Session::ClearOutgoing(int status) {
15291529

15301530
// Now that we've finished sending queued data, if there are any pending
15311531
// RstStreams we should try sending again and then flush them one by one.
1532-
if (pending_rst_streams_.size() > 0) {
1532+
if (!pending_rst_streams_.empty()) {
15331533
std::vector<int32_t> current_pending_rst_streams;
15341534
pending_rst_streams_.swap(current_pending_rst_streams);
15351535

@@ -1588,8 +1588,8 @@ uint8_t Http2Session::SendPendingData() {
15881588
ssize_t src_length;
15891589
const uint8_t* src;
15901590

1591-
CHECK_EQ(outgoing_buffers_.size(), 0);
1592-
CHECK_EQ(outgoing_storage_.size(), 0);
1591+
CHECK(outgoing_buffers_.empty());
1592+
CHECK(outgoing_storage_.empty());
15931593

15941594
// Part One: Gather data from nghttp2
15951595

src/node_url.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ bool ParseHost(const std::string& input,
11691169
std::string* output,
11701170
bool is_special,
11711171
bool unicode = false) {
1172-
if (input.length() == 0) {
1172+
if (input.empty()) {
11731173
output->clear();
11741174
return true;
11751175
}
@@ -2036,7 +2036,7 @@ void URL::Parse(const char* input,
20362036
(ch == kEOL ||
20372037
ch == '?' ||
20382038
ch == '#')) {
2039-
while (url->path.size() > 1 && url->path[0].length() == 0) {
2039+
while (url->path.size() > 1 && url->path[0].empty()) {
20402040
url->path.erase(url->path.begin());
20412041
}
20422042
}
@@ -2059,9 +2059,9 @@ void URL::Parse(const char* input,
20592059
state = kFragment;
20602060
break;
20612061
default:
2062-
if (url->path.size() == 0)
2062+
if (url->path.empty())
20632063
url->path.emplace_back("");
2064-
if (url->path.size() > 0 && ch != kEOL)
2064+
else if (ch != kEOL)
20652065
AppendOrEscape(&url->path[0], ch, C0_CONTROL_ENCODE_SET);
20662066
}
20672067
break;

src/node_worker.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
501501
per_isolate_opts.get(),
502502
kAllowedInEnvironment,
503503
&errors);
504-
if (errors.size() > 0 && args[1]->IsObject()) {
504+
if (!errors.empty() && args[1]->IsObject()) {
505505
// Only fail for explicitly provided env, this protects from failures
506506
// when NODE_OPTIONS from parent's env is used (which is the default).
507507
Local<Value> error;

0 commit comments

Comments
 (0)