Merge pull request #24444 from veblush/tidy-readability-container-size-empty

[Clang-Tidy] Enable readability-container-size-empty
pull/24409/head
Esun Kim 4 years ago committed by GitHub
commit dfd89da007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .clang-tidy
  2. 2
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  3. 2
      src/core/ext/filters/load_reporting/server_load_reporting_filter.cc
  4. 8
      src/core/ext/xds/xds_api.cc
  5. 2
      src/cpp/server/load_reporter/load_data_store.cc
  6. 2
      src/cpp/server/load_reporter/load_reporter.cc
  7. 2
      test/cpp/end2end/client_lb_end2end_test.cc
  8. 2
      test/cpp/end2end/flaky_network_test.cc
  9. 4
      test/cpp/end2end/mock_test.cc
  10. 2
      test/cpp/end2end/proto_server_reflection_test.cc
  11. 2
      test/cpp/interop/client.cc
  12. 4
      test/cpp/microbenchmarks/bm_call_create.cc
  13. 14
      test/cpp/naming/resolver_component_test.cc
  14. 4
      test/cpp/naming/resolver_component_tests_runner_invoker.cc
  15. 2
      test/cpp/qps/benchmark_config.cc
  16. 6
      test/cpp/qps/driver.cc
  17. 8
      test/cpp/qps/qps_json_driver.cc
  18. 2
      test/cpp/util/create_test_channel.cc

@ -30,7 +30,7 @@ Checks: '-*,
modernize-use-bool-literals, modernize-use-bool-literals,
modernize-use-nullptr, modernize-use-nullptr,
-modernize-use-override, -modernize-use-override,
-readability-container-size-empty, readability-container-size-empty,
readability-deleted-default, readability-deleted-default,
readability-function-size, readability-function-size,
-readability-inconsistent-declaration-parameter-name, -readability-inconsistent-declaration-parameter-name,

@ -941,7 +941,7 @@ void GrpcLb::BalancerCallState::SendClientLoadReportLocked() {
if (num_calls_started == 0 && num_calls_finished == 0 && if (num_calls_started == 0 && num_calls_finished == 0 &&
num_calls_finished_with_client_failed_to_send == 0 && num_calls_finished_with_client_failed_to_send == 0 &&
num_calls_finished_known_received == 0 && num_calls_finished_known_received == 0 &&
(drop_token_counts == nullptr || drop_token_counts->size() == 0)) { (drop_token_counts == nullptr || drop_token_counts->empty())) {
if (last_client_load_report_counters_were_zero_) { if (last_client_load_report_counters_were_zero_) {
ScheduleNextClientLoadReportLocked(); ScheduleNextClientLoadReportLocked();
return; return;

@ -180,7 +180,7 @@ void ServerLoadReportingCallData::StoreClientIpAndLrToken(const char* lr_token,
gpr_zalloc(client_ip_and_lr_token_len_ * sizeof(char))); gpr_zalloc(client_ip_and_lr_token_len_ * sizeof(char)));
char* cur_pos = client_ip_and_lr_token_; char* cur_pos = client_ip_and_lr_token_;
// Store the IP length prefix. // Store the IP length prefix.
if (client_ip.size() == 0) { if (client_ip.empty()) {
strncpy(cur_pos, kEmptyAddressLengthString, kLengthPrefixSize); strncpy(cur_pos, kEmptyAddressLengthString, kLengthPrefixSize);
} else if (client_ip.size() == 8) { } else if (client_ip.size() == 8) {
strncpy(cur_pos, kEncodedIpv4AddressLengthString, kLengthPrefixSize); strncpy(cur_pos, kEncodedIpv4AddressLengthString, kLengthPrefixSize);

@ -873,7 +873,7 @@ grpc_error* RoutePathMatchParse(const envoy_config_route_v3_RouteMatch* match,
absl::string_view prefix = absl::string_view prefix =
UpbStringToAbsl(envoy_config_route_v3_RouteMatch_prefix(match)); UpbStringToAbsl(envoy_config_route_v3_RouteMatch_prefix(match));
// Empty prefix "" is accepted. // Empty prefix "" is accepted.
if (prefix.size() > 0) { if (!prefix.empty()) {
// Prefix "/" is accepted. // Prefix "/" is accepted.
if (prefix[0] != '/') { if (prefix[0] != '/') {
// Prefix which does not start with a / will never match anything, so // Prefix which does not start with a / will never match anything, so
@ -899,7 +899,7 @@ grpc_error* RoutePathMatchParse(const envoy_config_route_v3_RouteMatch* match,
} else if (envoy_config_route_v3_RouteMatch_has_path(match)) { } else if (envoy_config_route_v3_RouteMatch_has_path(match)) {
absl::string_view path = absl::string_view path =
UpbStringToAbsl(envoy_config_route_v3_RouteMatch_path(match)); UpbStringToAbsl(envoy_config_route_v3_RouteMatch_path(match));
if (path.size() == 0) { if (path.empty()) {
// Path that is empty will never match anything, so ignore this route. // Path that is empty will never match anything, so ignore this route.
*ignore_route = true; *ignore_route = true;
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
@ -1068,7 +1068,7 @@ grpc_error* RouteActionParse(const envoy_config_route_v3_Route* route_msg,
if (envoy_config_route_v3_RouteAction_has_cluster(route_action)) { if (envoy_config_route_v3_RouteAction_has_cluster(route_action)) {
route->cluster_name = UpbStringToStdString( route->cluster_name = UpbStringToStdString(
envoy_config_route_v3_RouteAction_cluster(route_action)); envoy_config_route_v3_RouteAction_cluster(route_action));
if (route->cluster_name.size() == 0) { if (route->cluster_name.empty()) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING( return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"RouteAction cluster contains empty cluster name."); "RouteAction cluster contains empty cluster name.");
} }
@ -1650,7 +1650,7 @@ grpc_error* DropParseAndAppend(
std::string category = UpbStringToStdString( std::string category = UpbStringToStdString(
envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_category( envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_category(
drop_overload)); drop_overload));
if (category.size() == 0) { if (category.empty()) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty drop category name"); return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty drop category name");
} }
// Get the drop rate (per million). // Get the drop rate (per million).

@ -43,7 +43,7 @@ bool UnorderedMapOfSetEraseKeyValue(std::unordered_map<K, std::set<V>>& map,
auto it = map.find(key); auto it = map.find(key);
if (it != map.end()) { if (it != map.end()) {
size_t erased = it->second.erase(value); size_t erased = it->second.erase(value);
if (it->second.size() == 0) { if (it->second.empty()) {
map.erase(it); map.erase(it);
} }
return erased; return erased;

@ -431,7 +431,7 @@ void LoadReporter::ProcessViewDataCallEnd(
// This is due to a bug reported internally of Java server load reporting // This is due to a bug reported internally of Java server load reporting
// implementation. // implementation.
// TODO(juanlishen): Check whether this situation happens in OSS C++. // TODO(juanlishen): Check whether this situation happens in OSS C++.
if (client_ip_and_token.size() == 0) { if (client_ip_and_token.empty()) {
gpr_log(GPR_DEBUG, gpr_log(GPR_DEBUG,
"Skipping processing Opencensus record with empty " "Skipping processing Opencensus record with empty "
"client_ip_and_token tag."); "client_ip_and_token tag.");

@ -290,7 +290,7 @@ class ClientLbEnd2endTest : public ::testing::Test {
const std::string& lb_policy_name, const std::string& lb_policy_name,
const FakeResolverResponseGeneratorWrapper& response_generator, const FakeResolverResponseGeneratorWrapper& response_generator,
ChannelArguments args = ChannelArguments()) { ChannelArguments args = ChannelArguments()) {
if (lb_policy_name.size() > 0) { if (!lb_policy_name.empty()) {
args.SetLoadBalancingPolicyName(lb_policy_name); args.SetLoadBalancingPolicyName(lb_policy_name);
} // else, default to pick first } // else, default to pick first
args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR, args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,

@ -193,7 +193,7 @@ class FlakyNetworkTest : public ::testing::TestWithParam<TestScenario> {
std::shared_ptr<Channel> BuildChannel( std::shared_ptr<Channel> BuildChannel(
const std::string& lb_policy_name, const std::string& lb_policy_name,
ChannelArguments args = ChannelArguments()) { ChannelArguments args = ChannelArguments()) {
if (lb_policy_name.size() > 0) { if (!lb_policy_name.empty()) {
args.SetLoadBalancingPolicyName(lb_policy_name); args.SetLoadBalancingPolicyName(lb_policy_name);
} // else, default to pick first } // else, default to pick first
auto channel_creds = GetCredentialsProvider()->GetChannelCredentials( auto channel_creds = GetCredentialsProvider()->GetChannelCredentials(

@ -299,11 +299,11 @@ class TestServiceImpl : public EchoTestService::Service {
buff += n; buff += n;
continue; continue;
} }
if (buff == "") continue; if (buff.empty()) continue;
result.push_back(buff); result.push_back(buff);
buff = ""; buff = "";
} }
if (buff != "") result.push_back(buff); if (!buff.empty()) result.push_back(buff);
return result; return result;
} }

@ -133,7 +133,7 @@ TEST_F(ProtoServerReflectionTest, CheckResponseWithLocalDescriptorPool) {
std::vector<std::string> services; std::vector<std::string> services;
desc_db_->GetServices(&services); desc_db_->GetServices(&services);
// The service list has at least one service (reflection servcie). // The service list has at least one service (reflection servcie).
EXPECT_TRUE(services.size() > 0); EXPECT_TRUE(!services.empty());
for (auto it = services.begin(); it != services.end(); ++it) { for (auto it = services.begin(); it != services.end(); ++it) {
CompareService(*it); CompareService(*it);

@ -179,7 +179,7 @@ int main(int argc, char** argv) {
grpc::testing::ChannelCreationFunc channel_creation_func; grpc::testing::ChannelCreationFunc channel_creation_func;
std::string test_case = FLAGS_test_case; std::string test_case = FLAGS_test_case;
if (FLAGS_additional_metadata == "") { if (FLAGS_additional_metadata.empty()) {
channel_creation_func = [test_case]() { channel_creation_func = [test_case]() {
return CreateChannelForTestCase(test_case); return CreateChannelForTestCase(test_case);
}; };

@ -508,13 +508,13 @@ static void BM_IsolatedFilter(benchmark::State& state) {
grpc_core::ExecCtx exec_ctx; grpc_core::ExecCtx exec_ctx;
size_t channel_size = grpc_channel_stack_size( size_t channel_size = grpc_channel_stack_size(
filters.size() == 0 ? nullptr : &filters[0], filters.size()); filters.empty() ? nullptr : &filters[0], filters.size());
grpc_channel_stack* channel_stack = grpc_channel_stack* channel_stack =
static_cast<grpc_channel_stack*>(gpr_zalloc(channel_size)); static_cast<grpc_channel_stack*>(gpr_zalloc(channel_size));
GPR_ASSERT(GRPC_LOG_IF_ERROR( GPR_ASSERT(GRPC_LOG_IF_ERROR(
"channel_stack_init", "channel_stack_init",
grpc_channel_stack_init(1, FilterDestroy, channel_stack, grpc_channel_stack_init(1, FilterDestroy, channel_stack,
filters.size() == 0 ? nullptr : &filters[0], filters.empty() ? nullptr : &filters[0],
filters.size(), &channel_args, filters.size(), &channel_args,
fixture.flags & REQUIRES_TRANSPORT fixture.flags & REQUIRES_TRANSPORT
? &dummy_transport::dummy_transport ? &dummy_transport::dummy_transport

@ -161,7 +161,7 @@ class GrpcLBAddress final {
vector<GrpcLBAddress> ParseExpectedAddrs(std::string expected_addrs) { vector<GrpcLBAddress> ParseExpectedAddrs(std::string expected_addrs) {
std::vector<GrpcLBAddress> out; std::vector<GrpcLBAddress> out;
while (expected_addrs.size() != 0) { while (!expected_addrs.empty()) {
// get the next <ip>,<port> (v4 or v6) // get the next <ip>,<port> (v4 or v6)
size_t next_comma = expected_addrs.find(','); size_t next_comma = expected_addrs.find(',');
if (next_comma == std::string::npos) { if (next_comma == std::string::npos) {
@ -185,7 +185,7 @@ vector<GrpcLBAddress> ParseExpectedAddrs(std::string expected_addrs) {
expected_addrs = expected_addrs =
expected_addrs.substr(next_semicolon + 1, std::string::npos); expected_addrs.substr(next_semicolon + 1, std::string::npos);
} }
if (out.size() == 0) { if (out.empty()) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"expected_addrs arg should be a semicolon-separated list of " "expected_addrs arg should be a semicolon-separated list of "
"<ip-port>,<bool> pairs"); "<ip-port>,<bool> pairs");
@ -275,11 +275,11 @@ void PollPollsetUntilRequestDone(ArgsStruct* args) {
void CheckServiceConfigResultLocked(const char* service_config_json, void CheckServiceConfigResultLocked(const char* service_config_json,
grpc_error* service_config_error, grpc_error* service_config_error,
ArgsStruct* args) { ArgsStruct* args) {
if (args->expected_service_config_string != "") { if (!args->expected_service_config_string.empty()) {
GPR_ASSERT(service_config_json != nullptr); GPR_ASSERT(service_config_json != nullptr);
EXPECT_EQ(service_config_json, args->expected_service_config_string); EXPECT_EQ(service_config_json, args->expected_service_config_string);
} }
if (args->expected_service_config_error == "") { if (args->expected_service_config_error.empty()) {
EXPECT_EQ(service_config_error, GRPC_ERROR_NONE); EXPECT_EQ(service_config_error, GRPC_ERROR_NONE);
} else { } else {
EXPECT_THAT(grpc_error_string(service_config_error), EXPECT_THAT(grpc_error_string(service_config_error),
@ -292,7 +292,7 @@ void CheckLBPolicyResultLocked(const grpc_channel_args* channel_args,
ArgsStruct* args) { ArgsStruct* args) {
const grpc_arg* lb_policy_arg = const grpc_arg* lb_policy_arg =
grpc_channel_args_find(channel_args, GRPC_ARG_LB_POLICY_NAME); grpc_channel_args_find(channel_args, GRPC_ARG_LB_POLICY_NAME);
if (args->expected_lb_policy != "") { if (!args->expected_lb_policy.empty()) {
GPR_ASSERT(lb_policy_arg != nullptr); GPR_ASSERT(lb_policy_arg != nullptr);
GPR_ASSERT(lb_policy_arg->type == GRPC_ARG_STRING); GPR_ASSERT(lb_policy_arg->type == GRPC_ARG_STRING);
EXPECT_EQ(lb_policy_arg->value.string, args->expected_lb_policy); EXPECT_EQ(lb_policy_arg->value.string, args->expected_lb_policy);
@ -513,7 +513,7 @@ class CheckingResultHandler : public ResultHandler {
: result.service_config->json_string().c_str(); : result.service_config->json_string().c_str();
CheckServiceConfigResultLocked( CheckServiceConfigResultLocked(
service_config_json, GRPC_ERROR_REF(result.service_config_error), args); service_config_json, GRPC_ERROR_REF(result.service_config_error), args);
if (args->expected_service_config_string == "") { if (args->expected_service_config_string.empty()) {
CheckLBPolicyResultLocked(result.args, args); CheckLBPolicyResultLocked(result.args, args);
} }
} }
@ -678,7 +678,7 @@ int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(argc, argv); grpc::testing::TestEnvironment env(argc, argv);
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
grpc::testing::InitTest(&argc, &argv, true); grpc::testing::InitTest(&argc, &argv, true);
if (FLAGS_target_name == "") { if (FLAGS_target_name.empty()) {
gpr_log(GPR_ERROR, "Missing target_name param."); gpr_log(GPR_ERROR, "Missing target_name param.");
abort(); abort();
} }

@ -164,10 +164,10 @@ int main(int argc, char** argv) {
grpc::testing::TestEnvironment env(argc, argv); grpc::testing::TestEnvironment env(argc, argv);
grpc::testing::InitTest(&argc, &argv, true); grpc::testing::InitTest(&argc, &argv, true);
grpc_init(); grpc_init();
GPR_ASSERT(FLAGS_test_bin_name != ""); GPR_ASSERT(!FLAGS_test_bin_name.empty());
std::string my_bin = argv[0]; std::string my_bin = argv[0];
if (FLAGS_running_under_bazel) { if (FLAGS_running_under_bazel) {
GPR_ASSERT(FLAGS_grpc_test_directory_relative_to_test_srcdir != ""); GPR_ASSERT(!FLAGS_grpc_test_directory_relative_to_test_srcdir.empty());
// Use bazel's TEST_SRCDIR environment variable to locate the "test data" // Use bazel's TEST_SRCDIR environment variable to locate the "test data"
// binaries. // binaries.
char* test_srcdir = gpr_getenv("TEST_SRCDIR"); char* test_srcdir = gpr_getenv("TEST_SRCDIR");

@ -66,7 +66,7 @@ static std::shared_ptr<Reporter> InitBenchmarkReporters() {
composite_reporter->add( composite_reporter->add(
std::unique_ptr<Reporter>(new GprLogReporter("LogReporter"))); std::unique_ptr<Reporter>(new GprLogReporter("LogReporter")));
} }
if (FLAGS_scenario_result_file != "") { if (!FLAGS_scenario_result_file.empty()) {
composite_reporter->add(std::unique_ptr<Reporter>( composite_reporter->add(std::unique_ptr<Reporter>(
new JsonReporter("JsonReporter", FLAGS_scenario_result_file))); new JsonReporter("JsonReporter", FLAGS_scenario_result_file)));
} }

@ -77,7 +77,7 @@ static deque<string> get_workers(const string& env_name) {
} }
} }
} }
if (out.size() == 0) { if (out.empty()) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"Environment variable \"%s\" does not contain a list of QPS " "Environment variable \"%s\" does not contain a list of QPS "
"workers to use. Set it to a comma-separated list of " "workers to use. Set it to a comma-separated list of "
@ -410,7 +410,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
workers.push_back(addr); workers.push_back(addr);
} }
} }
GPR_ASSERT(workers.size() != 0); GPR_ASSERT(!workers.empty());
// if num_clients is set to <=0, do dynamic sizing: all workers // if num_clients is set to <=0, do dynamic sizing: all workers
// except for servers are clients // except for servers are clients
@ -656,7 +656,7 @@ bool RunQuit(
// Get client, server lists // Get client, server lists
bool result = true; bool result = true;
auto workers = get_workers("QPS_WORKERS"); auto workers = get_workers("QPS_WORKERS");
if (workers.size() == 0) { if (workers.empty()) {
return false; return false;
} }

@ -153,7 +153,7 @@ static std::unique_ptr<ScenarioResult> RunAndReport(
*success = result->server_success(i); *success = result->server_success(i);
} }
if (FLAGS_json_file_out != "") { if (!FLAGS_json_file_out.empty()) {
std::ofstream json_outfile; std::ofstream json_outfile;
json_outfile.open(FLAGS_json_file_out); json_outfile.open(FLAGS_json_file_out);
json_outfile << "{\"qps\": " << result->summary().qps() << "}\n"; json_outfile << "{\"qps\": " << result->summary().qps() << "}\n";
@ -229,8 +229,8 @@ static double SearchOfferedLoad(
static bool QpsDriver() { static bool QpsDriver() {
std::string json; std::string json;
bool scfile = (FLAGS_scenarios_file != ""); bool scfile = (!FLAGS_scenarios_file.empty());
bool scjson = (FLAGS_scenarios_json != ""); bool scjson = (!FLAGS_scenarios_json.empty());
if ((!scfile && !scjson && !FLAGS_quit) || if ((!scfile && !scjson && !FLAGS_quit) ||
(scfile && (scjson || FLAGS_quit)) || (scjson && FLAGS_quit)) { (scfile && (scjson || FLAGS_quit)) || (scjson && FLAGS_quit)) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
@ -267,7 +267,7 @@ static bool QpsDriver() {
GPR_ASSERT(scenarios.scenarios_size() > 0); GPR_ASSERT(scenarios.scenarios_size() > 0);
for (int i = 0; i < scenarios.scenarios_size(); i++) { for (int i = 0; i < scenarios.scenarios_size(); i++) {
if (FLAGS_search_param == "") { if (FLAGS_search_param.empty()) {
const Scenario& scenario = scenarios.scenarios(i); const Scenario& scenario = scenarios.scenarios(i);
RunAndReport(scenario, per_worker_credential_types, &success); RunAndReport(scenario, per_worker_credential_types, &success);
} else { } else {

@ -59,7 +59,7 @@ void AddProdSslType() {
} }
void MaybeSetCustomChannelArgs(grpc::ChannelArguments* args) { void MaybeSetCustomChannelArgs(grpc::ChannelArguments* args) {
if (FLAGS_grpc_test_use_grpclb_with_child_policy.size() > 0) { if (!FLAGS_grpc_test_use_grpclb_with_child_policy.empty()) {
args->SetString("grpc.service_config", args->SetString("grpc.service_config",
"{\"loadBalancingConfig\":[{\"grpclb\":{\"childPolicy\":[{" "{\"loadBalancingConfig\":[{\"grpclb\":{\"childPolicy\":[{"
"\"" + "\"" +

Loading…
Cancel
Save