Use C++11 range-based fors

pull/20626/head
Vijay Pai 5 years ago
parent 72475f48a0
commit b7705ce2ee
  1. 37
      src/cpp/common/channel_arguments.cc
  2. 10
      src/cpp/common/tls_credentials_options.cc
  3. 8
      src/cpp/common/tls_credentials_options_util.cc

@ -39,26 +39,26 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other)
args_.reserve(other.args_.size());
auto list_it_dst = strings_.begin();
auto list_it_src = other.strings_.begin();
for (auto a = other.args_.begin(); a != other.args_.end(); ++a) {
for (const auto& a : other.args_) {
grpc_arg ap;
ap.type = a->type;
GPR_ASSERT(list_it_src->c_str() == a->key);
ap.type = a.type;
GPR_ASSERT(list_it_src->c_str() == a.key);
ap.key = const_cast<char*>(list_it_dst->c_str());
++list_it_src;
++list_it_dst;
switch (a->type) {
switch (a.type) {
case GRPC_ARG_INTEGER:
ap.value.integer = a->value.integer;
ap.value.integer = a.value.integer;
break;
case GRPC_ARG_STRING:
GPR_ASSERT(list_it_src->c_str() == a->value.string);
GPR_ASSERT(list_it_src->c_str() == a.value.string);
ap.value.string = const_cast<char*>(list_it_dst->c_str());
++list_it_src;
++list_it_dst;
break;
case GRPC_ARG_POINTER:
ap.value.pointer = a->value.pointer;
ap.value.pointer.p = a->value.pointer.vtable->copy(ap.value.pointer.p);
ap.value.pointer = a.value.pointer;
ap.value.pointer.p = a.value.pointer.vtable->copy(ap.value.pointer.p);
break;
}
args_.push_back(ap);
@ -67,9 +67,9 @@ ChannelArguments::ChannelArguments(const ChannelArguments& other)
ChannelArguments::~ChannelArguments() {
grpc_core::ExecCtx exec_ctx;
for (auto it = args_.begin(); it != args_.end(); ++it) {
if (it->type == GRPC_ARG_POINTER) {
it->value.pointer.vtable->destroy(it->value.pointer.p);
for (auto& arg : args_) {
if (arg.type == GRPC_ARG_POINTER) {
arg.value.pointer.vtable->destroy(arg.value.pointer.p);
}
}
}
@ -95,12 +95,12 @@ void ChannelArguments::SetSocketMutator(grpc_socket_mutator* mutator) {
grpc_arg mutator_arg = grpc_socket_mutator_to_arg(mutator);
bool replaced = false;
grpc_core::ExecCtx exec_ctx;
for (auto it = args_.begin(); it != args_.end(); ++it) {
if (it->type == mutator_arg.type &&
grpc::string(it->key) == grpc::string(mutator_arg.key)) {
for (auto& arg : args_) {
if (arg.type == mutator_arg.type &&
grpc::string(arg.key) == grpc::string(mutator_arg.key)) {
GPR_ASSERT(!replaced);
it->value.pointer.vtable->destroy(it->value.pointer.p);
it->value.pointer = mutator_arg.value.pointer;
arg.value.pointer.vtable->destroy(arg.value.pointer.p);
arg.value.pointer = mutator_arg.value.pointer;
replaced = true;
}
}
@ -123,14 +123,13 @@ void ChannelArguments::SetUserAgentPrefix(
}
bool replaced = false;
auto strings_it = strings_.begin();
for (auto it = args_.begin(); it != args_.end(); ++it) {
const grpc_arg& arg = *it;
for (auto& arg : args_) {
++strings_it;
if (arg.type == GRPC_ARG_STRING) {
if (grpc::string(arg.key) == GRPC_ARG_PRIMARY_USER_AGENT_STRING) {
GPR_ASSERT(arg.value.string == strings_it->c_str());
*(strings_it) = user_agent_prefix + " " + arg.value.string;
it->value.string = const_cast<char*>(strings_it->c_str());
arg.value.string = const_cast<char*>(strings_it->c_str());
replaced = true;
break;
}

@ -106,15 +106,13 @@ void TlsCredentialReloadArg::set_key_materials_config(
}
::grpc_core::InlinedVector<::grpc_core::PemKeyCertPair, 1>
c_pem_key_cert_pair_list;
for (auto key_cert_pair =
key_materials_config->pem_key_cert_pair_list().begin();
key_cert_pair != key_materials_config->pem_key_cert_pair_list().end();
key_cert_pair++) {
for (const auto& key_cert_pair :
key_materials_config->pem_key_cert_pair_list()) {
grpc_ssl_pem_key_cert_pair* ssl_pair =
(grpc_ssl_pem_key_cert_pair*)gpr_malloc(
sizeof(grpc_ssl_pem_key_cert_pair));
ssl_pair->private_key = gpr_strdup(key_cert_pair->private_key.c_str());
ssl_pair->cert_chain = gpr_strdup(key_cert_pair->cert_chain.c_str());
ssl_pair->private_key = gpr_strdup(key_cert_pair.private_key.c_str());
ssl_pair->cert_chain = gpr_strdup(key_cert_pair.cert_chain.c_str());
::grpc_core::PemKeyCertPair c_pem_key_cert_pair =
::grpc_core::PemKeyCertPair(ssl_pair);
c_pem_key_cert_pair_list.emplace_back(std::move(c_pem_key_cert_pair));

@ -36,14 +36,12 @@ grpc_tls_key_materials_config* ConvertToCKeyMaterialsConfig(
grpc_tls_key_materials_config_create();
::grpc_core::InlinedVector<::grpc_core::PemKeyCertPair, 1>
c_pem_key_cert_pair_list;
for (auto key_cert_pair = config->pem_key_cert_pair_list().begin();
key_cert_pair != config->pem_key_cert_pair_list().end();
key_cert_pair++) {
for (const auto& key_cert_pair : config->pem_key_cert_pair_list()) {
grpc_ssl_pem_key_cert_pair* ssl_pair =
(grpc_ssl_pem_key_cert_pair*)gpr_malloc(
sizeof(grpc_ssl_pem_key_cert_pair));
ssl_pair->private_key = gpr_strdup(key_cert_pair->private_key.c_str());
ssl_pair->cert_chain = gpr_strdup(key_cert_pair->cert_chain.c_str());
ssl_pair->private_key = gpr_strdup(key_cert_pair.private_key.c_str());
ssl_pair->cert_chain = gpr_strdup(key_cert_pair.cert_chain.c_str());
::grpc_core::PemKeyCertPair c_pem_key_cert_pair =
::grpc_core::PemKeyCertPair(ssl_pair);
c_pem_key_cert_pair_list.push_back(::std::move(c_pem_key_cert_pair));

Loading…
Cancel
Save