Skip to content

Commit 541fb1b

Browse files
tniessenaddaleax
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 898947b commit 541fb1b

6 files changed

+12
-12
lines changed

src/inspector_agent.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ bool IsFilePath(const std::string& path) {
455455
}
456456
#else
457457
bool IsFilePath(const std::string& path) {
458-
return path.length() && path[0] == '/';
458+
return !path.empty() && path[0] == '/';
459459
}
460460
#endif // __POSIX__
461461

src/inspector_js_api.cc

+1-1
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

+1-1
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ void Http2Session::ClearOutgoing(int status) {
15891589

15901590
flags_ &= ~SESSION_STATE_SENDING;
15911591

1592-
if (outgoing_buffers_.size() > 0) {
1592+
if (!outgoing_buffers_.empty()) {
15931593
outgoing_storage_.clear();
15941594
outgoing_length_ = 0;
15951595

@@ -1608,7 +1608,7 @@ void Http2Session::ClearOutgoing(int status) {
16081608

16091609
// Now that we've finished sending queued data, if there are any pending
16101610
// RstStreams we should try sending again and then flush them one by one.
1611-
if (pending_rst_streams_.size() > 0) {
1611+
if (!pending_rst_streams_.empty()) {
16121612
std::vector<int32_t> current_pending_rst_streams;
16131613
pending_rst_streams_.swap(current_pending_rst_streams);
16141614

@@ -1667,8 +1667,8 @@ uint8_t Http2Session::SendPendingData() {
16671667
ssize_t src_length;
16681668
const uint8_t* src;
16691669

1670-
CHECK_EQ(outgoing_buffers_.size(), 0);
1671-
CHECK_EQ(outgoing_storage_.size(), 0);
1670+
CHECK(outgoing_buffers_.empty());
1671+
CHECK(outgoing_storage_.empty());
16721672

16731673
// Part One: Gather data from nghttp2
16741674

src/node_url.cc

+4-4
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
528528
per_isolate_opts.get(),
529529
kAllowedInEnvironment,
530530
&errors);
531-
if (errors.size() > 0 && args[1]->IsObject()) {
531+
if (!errors.empty() && args[1]->IsObject()) {
532532
// Only fail for explicitly provided env, this protects from failures
533533
// when NODE_OPTIONS from parent's env is used (which is the default).
534534
Local<Value> error;

0 commit comments

Comments
 (0)