Fix code by readability-container-size-empty
This commit is contained in:
parent
aed0a7ddb3
commit
ece76ee1e8
|
|
@ -941,7 +941,7 @@ void GrpcLb::BalancerCallState::SendClientLoadReportLocked() {
|
|||
if (num_calls_started == 0 && num_calls_finished == 0 &&
|
||||
num_calls_finished_with_client_failed_to_send == 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_) {
|
||||
ScheduleNextClientLoadReportLocked();
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ void ServerLoadReportingCallData::StoreClientIpAndLrToken(const char* lr_token,
|
|||
gpr_zalloc(client_ip_and_lr_token_len_ * sizeof(char)));
|
||||
char* cur_pos = client_ip_and_lr_token_;
|
||||
// Store the IP length prefix.
|
||||
if (client_ip.size() == 0) {
|
||||
if (client_ip.empty()) {
|
||||
strncpy(cur_pos, kEmptyAddressLengthString, kLengthPrefixSize);
|
||||
} else if (client_ip.size() == 8) {
|
||||
strncpy(cur_pos, kEncodedIpv4AddressLengthString, kLengthPrefixSize);
|
||||
|
|
|
|||
|
|
@ -873,7 +873,7 @@ grpc_error* RoutePathMatchParse(const envoy_config_route_v3_RouteMatch* match,
|
|||
absl::string_view prefix =
|
||||
UpbStringToAbsl(envoy_config_route_v3_RouteMatch_prefix(match));
|
||||
// Empty prefix "" is accepted.
|
||||
if (prefix.size() > 0) {
|
||||
if (!prefix.empty()) {
|
||||
// Prefix "/" is accepted.
|
||||
if (prefix[0] != '/') {
|
||||
// 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)) {
|
||||
absl::string_view path =
|
||||
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.
|
||||
*ignore_route = true;
|
||||
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)) {
|
||||
route->cluster_name = UpbStringToStdString(
|
||||
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(
|
||||
"RouteAction cluster contains empty cluster name.");
|
||||
}
|
||||
|
|
@ -1650,7 +1650,7 @@ grpc_error* DropParseAndAppend(
|
|||
std::string category = UpbStringToStdString(
|
||||
envoy_config_endpoint_v3_ClusterLoadAssignment_Policy_DropOverload_category(
|
||||
drop_overload));
|
||||
if (category.size() == 0) {
|
||||
if (category.empty()) {
|
||||
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Empty drop category name");
|
||||
}
|
||||
// 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);
|
||||
if (it != map.end()) {
|
||||
size_t erased = it->second.erase(value);
|
||||
if (it->second.size() == 0) {
|
||||
if (it->second.empty()) {
|
||||
map.erase(it);
|
||||
}
|
||||
return erased;
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ void LoadReporter::ProcessViewDataCallEnd(
|
|||
// This is due to a bug reported internally of Java server load reporting
|
||||
// implementation.
|
||||
// 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,
|
||||
"Skipping processing Opencensus record with empty "
|
||||
"client_ip_and_token tag.");
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ class ClientLbEnd2endTest : public ::testing::Test {
|
|||
const std::string& lb_policy_name,
|
||||
const FakeResolverResponseGeneratorWrapper& response_generator,
|
||||
ChannelArguments args = ChannelArguments()) {
|
||||
if (lb_policy_name.size() > 0) {
|
||||
if (!lb_policy_name.empty()) {
|
||||
args.SetLoadBalancingPolicyName(lb_policy_name);
|
||||
} // else, default to pick first
|
||||
args.SetPointer(GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ class FlakyNetworkTest : public ::testing::TestWithParam<TestScenario> {
|
|||
std::shared_ptr<Channel> BuildChannel(
|
||||
const std::string& lb_policy_name,
|
||||
ChannelArguments args = ChannelArguments()) {
|
||||
if (lb_policy_name.size() > 0) {
|
||||
if (!lb_policy_name.empty()) {
|
||||
args.SetLoadBalancingPolicyName(lb_policy_name);
|
||||
} // else, default to pick first
|
||||
auto channel_creds = GetCredentialsProvider()->GetChannelCredentials(
|
||||
|
|
|
|||
|
|
@ -299,11 +299,11 @@ class TestServiceImpl : public EchoTestService::Service {
|
|||
buff += n;
|
||||
continue;
|
||||
}
|
||||
if (buff == "") continue;
|
||||
if (buff.empty()) continue;
|
||||
result.push_back(buff);
|
||||
buff = "";
|
||||
}
|
||||
if (buff != "") result.push_back(buff);
|
||||
if (!buff.empty()) result.push_back(buff);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ TEST_F(ProtoServerReflectionTest, CheckResponseWithLocalDescriptorPool) {
|
|||
std::vector<std::string> services;
|
||||
desc_db_->GetServices(&services);
|
||||
// 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) {
|
||||
CompareService(*it);
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
grpc::testing::ChannelCreationFunc channel_creation_func;
|
||||
std::string test_case = FLAGS_test_case;
|
||||
if (FLAGS_additional_metadata == "") {
|
||||
if (FLAGS_additional_metadata.empty()) {
|
||||
channel_creation_func = [test_case]() {
|
||||
return CreateChannelForTestCase(test_case);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -508,13 +508,13 @@ static void BM_IsolatedFilter(benchmark::State& state) {
|
|||
|
||||
grpc_core::ExecCtx exec_ctx;
|
||||
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 =
|
||||
static_cast<grpc_channel_stack*>(gpr_zalloc(channel_size));
|
||||
GPR_ASSERT(GRPC_LOG_IF_ERROR(
|
||||
"channel_stack_init",
|
||||
grpc_channel_stack_init(1, FilterDestroy, channel_stack,
|
||||
filters.size() == 0 ? nullptr : &filters[0],
|
||||
filters.empty() ? nullptr : &filters[0],
|
||||
filters.size(), &channel_args,
|
||||
fixture.flags & REQUIRES_TRANSPORT
|
||||
? &dummy_transport::dummy_transport
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ class GrpcLBAddress final {
|
|||
|
||||
vector<GrpcLBAddress> ParseExpectedAddrs(std::string expected_addrs) {
|
||||
std::vector<GrpcLBAddress> out;
|
||||
while (expected_addrs.size() != 0) {
|
||||
while (!expected_addrs.empty()) {
|
||||
// get the next <ip>,<port> (v4 or v6)
|
||||
size_t next_comma = expected_addrs.find(',');
|
||||
if (next_comma == std::string::npos) {
|
||||
|
|
@ -185,7 +185,7 @@ vector<GrpcLBAddress> ParseExpectedAddrs(std::string expected_addrs) {
|
|||
expected_addrs =
|
||||
expected_addrs.substr(next_semicolon + 1, std::string::npos);
|
||||
}
|
||||
if (out.size() == 0) {
|
||||
if (out.empty()) {
|
||||
gpr_log(GPR_ERROR,
|
||||
"expected_addrs arg should be a semicolon-separated list of "
|
||||
"<ip-port>,<bool> pairs");
|
||||
|
|
@ -275,11 +275,11 @@ void PollPollsetUntilRequestDone(ArgsStruct* args) {
|
|||
void CheckServiceConfigResultLocked(const char* service_config_json,
|
||||
grpc_error* service_config_error,
|
||||
ArgsStruct* args) {
|
||||
if (args->expected_service_config_string != "") {
|
||||
if (!args->expected_service_config_string.empty()) {
|
||||
GPR_ASSERT(service_config_json != nullptr);
|
||||
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);
|
||||
} else {
|
||||
EXPECT_THAT(grpc_error_string(service_config_error),
|
||||
|
|
@ -292,7 +292,7 @@ void CheckLBPolicyResultLocked(const grpc_channel_args* channel_args,
|
|||
ArgsStruct* args) {
|
||||
const grpc_arg* lb_policy_arg =
|
||||
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->type == GRPC_ARG_STRING);
|
||||
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();
|
||||
CheckServiceConfigResultLocked(
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -678,7 +678,7 @@ int main(int argc, char** argv) {
|
|||
grpc::testing::TestEnvironment env(argc, argv);
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
grpc::testing::InitTest(&argc, &argv, true);
|
||||
if (FLAGS_target_name == "") {
|
||||
if (FLAGS_target_name.empty()) {
|
||||
gpr_log(GPR_ERROR, "Missing target_name param.");
|
||||
abort();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -164,10 +164,10 @@ int main(int argc, char** argv) {
|
|||
grpc::testing::TestEnvironment env(argc, argv);
|
||||
grpc::testing::InitTest(&argc, &argv, true);
|
||||
grpc_init();
|
||||
GPR_ASSERT(FLAGS_test_bin_name != "");
|
||||
GPR_ASSERT(!FLAGS_test_bin_name.empty());
|
||||
std::string my_bin = argv[0];
|
||||
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"
|
||||
// binaries.
|
||||
char* test_srcdir = gpr_getenv("TEST_SRCDIR");
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ static std::shared_ptr<Reporter> InitBenchmarkReporters() {
|
|||
composite_reporter->add(
|
||||
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>(
|
||||
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,
|
||||
"Environment variable \"%s\" does not contain a list of QPS "
|
||||
"workers to use. Set it to a comma-separated list of "
|
||||
|
|
@ -410,7 +410,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
|
|||
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
|
||||
// except for servers are clients
|
||||
|
|
@ -656,7 +656,7 @@ bool RunQuit(
|
|||
// Get client, server lists
|
||||
bool result = true;
|
||||
auto workers = get_workers("QPS_WORKERS");
|
||||
if (workers.size() == 0) {
|
||||
if (workers.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ static std::unique_ptr<ScenarioResult> RunAndReport(
|
|||
*success = result->server_success(i);
|
||||
}
|
||||
|
||||
if (FLAGS_json_file_out != "") {
|
||||
if (!FLAGS_json_file_out.empty()) {
|
||||
std::ofstream json_outfile;
|
||||
json_outfile.open(FLAGS_json_file_out);
|
||||
json_outfile << "{\"qps\": " << result->summary().qps() << "}\n";
|
||||
|
|
@ -229,8 +229,8 @@ static double SearchOfferedLoad(
|
|||
static bool QpsDriver() {
|
||||
std::string json;
|
||||
|
||||
bool scfile = (FLAGS_scenarios_file != "");
|
||||
bool scjson = (FLAGS_scenarios_json != "");
|
||||
bool scfile = (!FLAGS_scenarios_file.empty());
|
||||
bool scjson = (!FLAGS_scenarios_json.empty());
|
||||
if ((!scfile && !scjson && !FLAGS_quit) ||
|
||||
(scfile && (scjson || FLAGS_quit)) || (scjson && FLAGS_quit)) {
|
||||
gpr_log(GPR_ERROR,
|
||||
|
|
@ -267,7 +267,7 @@ static bool QpsDriver() {
|
|||
GPR_ASSERT(scenarios.scenarios_size() > 0);
|
||||
|
||||
for (int i = 0; i < scenarios.scenarios_size(); i++) {
|
||||
if (FLAGS_search_param == "") {
|
||||
if (FLAGS_search_param.empty()) {
|
||||
const Scenario& scenario = scenarios.scenarios(i);
|
||||
RunAndReport(scenario, per_worker_credential_types, &success);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ void AddProdSslType() {
|
|||
}
|
||||
|
||||
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",
|
||||
"{\"loadBalancingConfig\":[{\"grpclb\":{\"childPolicy\":[{"
|
||||
"\"" +
|
||||
|
|
|
|||
Loading…
Reference in New Issue