Skip to content

Commit 1be7bbd

Browse files
tniessenjasnell
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 f280d2c commit 1be7bbd

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
@@ -366,7 +366,7 @@ bool IsFilePath(const std::string& path) {
366366
}
367367
#else
368368
bool IsFilePath(const std::string& path) {
369-
return path.length() && path[0] == '/';
369+
return !path.empty() && path[0] == '/';
370370
}
371371
#endif // __POSIX__
372372

src/inspector_js_api.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ void WaitForDebugger(const FunctionCallbackInfo<Value>& args) {
303303
void Url(const FunctionCallbackInfo<Value>& args) {
304304
Environment* env = Environment::GetCurrent(args);
305305
std::string url = env->inspector_agent()->GetWsUrl();
306-
if (url.length() == 0) {
306+
if (url.empty()) {
307307
return;
308308
}
309309
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
@@ -1517,7 +1517,7 @@ void Http2Session::ClearOutgoing(int status) {
15171517

15181518
set_sending(false);
15191519

1520-
if (outgoing_buffers_.size() > 0) {
1520+
if (!outgoing_buffers_.empty()) {
15211521
outgoing_storage_.clear();
15221522
outgoing_length_ = 0;
15231523

@@ -1536,7 +1536,7 @@ void Http2Session::ClearOutgoing(int status) {
15361536

15371537
// Now that we've finished sending queued data, if there are any pending
15381538
// RstStreams we should try sending again and then flush them one by one.
1539-
if (pending_rst_streams_.size() > 0) {
1539+
if (!pending_rst_streams_.empty()) {
15401540
std::vector<int32_t> current_pending_rst_streams;
15411541
pending_rst_streams_.swap(current_pending_rst_streams);
15421542

@@ -1595,8 +1595,8 @@ uint8_t Http2Session::SendPendingData() {
15951595
ssize_t src_length;
15961596
const uint8_t* src;
15971597

1598-
CHECK_EQ(outgoing_buffers_.size(), 0);
1599-
CHECK_EQ(outgoing_storage_.size(), 0);
1598+
CHECK(outgoing_buffers_.empty());
1599+
CHECK(outgoing_storage_.empty());
16001600

16011601
// Part One: Gather data from nghttp2
16021602

src/node_url.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ bool ParseHost(const std::string& input,
11701170
std::string* output,
11711171
bool is_special,
11721172
bool unicode = false) {
1173-
if (input.length() == 0) {
1173+
if (input.empty()) {
11741174
output->clear();
11751175
return true;
11761176
}
@@ -2037,7 +2037,7 @@ void URL::Parse(const char* input,
20372037
(ch == kEOL ||
20382038
ch == '?' ||
20392039
ch == '#')) {
2040-
while (url->path.size() > 1 && url->path[0].length() == 0) {
2040+
while (url->path.size() > 1 && url->path[0].empty()) {
20412041
url->path.erase(url->path.begin());
20422042
}
20432043
}
@@ -2060,9 +2060,9 @@ void URL::Parse(const char* input,
20602060
state = kFragment;
20612061
break;
20622062
default:
2063-
if (url->path.size() == 0)
2063+
if (url->path.empty())
20642064
url->path.emplace_back("");
2065-
if (url->path.size() > 0 && ch != kEOL)
2065+
else if (ch != kEOL)
20662066
AppendOrEscape(&url->path[0], ch, C0_CONTROL_ENCODE_SET);
20672067
}
20682068
break;

src/node_worker.cc

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

0 commit comments

Comments
 (0)