Merge pull request #20440 from veblush/cpp-more

Use std::pair
pull/20451/head
Esun Kim 5 years ago committed by GitHub
commit 39c3747229
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      BUILD
  2. 2
      BUILD.gn
  3. 1
      build.yaml
  4. 1
      gRPC-C++.podspec
  5. 2
      gRPC-Core.podspec
  6. 1
      grpc.gemspec
  7. 1
      package.xml
  8. 4
      src/core/ext/filters/client_channel/lb_policy/xds/xds.cc
  9. 9
      src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc
  10. 2
      src/core/ext/filters/client_channel/subchannel.cc
  11. 8
      src/core/lib/channel/channelz.cc
  12. 6
      src/core/lib/gprpp/arena.cc
  13. 5
      src/core/lib/gprpp/arena.h
  14. 1
      src/core/lib/gprpp/map.h
  15. 38
      src/core/lib/gprpp/pair.h
  16. 2
      src/core/lib/transport/connectivity_state.cc
  17. 1
      tools/doxygen/Doxyfile.c++.internal
  18. 1
      tools/doxygen/Doxyfile.core.internal

@ -521,7 +521,6 @@ grpc_cc_library(
"src/core/lib/gprpp/map.h", "src/core/lib/gprpp/map.h",
"src/core/lib/gprpp/memory.h", "src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/mpscq.h", "src/core/lib/gprpp/mpscq.h",
"src/core/lib/gprpp/pair.h",
"src/core/lib/gprpp/string_view.h", "src/core/lib/gprpp/string_view.h",
"src/core/lib/gprpp/sync.h", "src/core/lib/gprpp/sync.h",
"src/core/lib/gprpp/thd.h", "src/core/lib/gprpp/thd.h",

@ -149,7 +149,6 @@ config("grpc_config") {
"src/core/lib/gprpp/memory.h", "src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/mpscq.cc", "src/core/lib/gprpp/mpscq.cc",
"src/core/lib/gprpp/mpscq.h", "src/core/lib/gprpp/mpscq.h",
"src/core/lib/gprpp/pair.h",
"src/core/lib/gprpp/sync.h", "src/core/lib/gprpp/sync.h",
"src/core/lib/gprpp/thd.h", "src/core/lib/gprpp/thd.h",
"src/core/lib/gprpp/thd_posix.cc", "src/core/lib/gprpp/thd_posix.cc",
@ -1252,7 +1251,6 @@ config("grpc_config") {
"src/core/lib/gprpp/mpscq.h", "src/core/lib/gprpp/mpscq.h",
"src/core/lib/gprpp/optional.h", "src/core/lib/gprpp/optional.h",
"src/core/lib/gprpp/orphanable.h", "src/core/lib/gprpp/orphanable.h",
"src/core/lib/gprpp/pair.h",
"src/core/lib/gprpp/ref_counted.h", "src/core/lib/gprpp/ref_counted.h",
"src/core/lib/gprpp/ref_counted_ptr.h", "src/core/lib/gprpp/ref_counted_ptr.h",
"src/core/lib/gprpp/string_view.h", "src/core/lib/gprpp/string_view.h",

@ -291,7 +291,6 @@ filegroups:
- src/core/lib/gprpp/map.h - src/core/lib/gprpp/map.h
- src/core/lib/gprpp/memory.h - src/core/lib/gprpp/memory.h
- src/core/lib/gprpp/mpscq.h - src/core/lib/gprpp/mpscq.h
- src/core/lib/gprpp/pair.h
- src/core/lib/gprpp/sync.h - src/core/lib/gprpp/sync.h
- src/core/lib/gprpp/thd.h - src/core/lib/gprpp/thd.h
- src/core/lib/profiling/timers.h - src/core/lib/profiling/timers.h

@ -311,7 +311,6 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/map.h', 'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h', 'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/mpscq.h', 'src/core/lib/gprpp/mpscq.h',
'src/core/lib/gprpp/pair.h',
'src/core/lib/gprpp/sync.h', 'src/core/lib/gprpp/sync.h',
'src/core/lib/gprpp/thd.h', 'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h', 'src/core/lib/profiling/timers.h',

@ -214,7 +214,6 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/map.h', 'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h', 'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/mpscq.h', 'src/core/lib/gprpp/mpscq.h',
'src/core/lib/gprpp/pair.h',
'src/core/lib/gprpp/sync.h', 'src/core/lib/gprpp/sync.h',
'src/core/lib/gprpp/thd.h', 'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h', 'src/core/lib/profiling/timers.h',
@ -989,7 +988,6 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/map.h', 'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h', 'src/core/lib/gprpp/memory.h',
'src/core/lib/gprpp/mpscq.h', 'src/core/lib/gprpp/mpscq.h',
'src/core/lib/gprpp/pair.h',
'src/core/lib/gprpp/sync.h', 'src/core/lib/gprpp/sync.h',
'src/core/lib/gprpp/thd.h', 'src/core/lib/gprpp/thd.h',
'src/core/lib/profiling/timers.h', 'src/core/lib/profiling/timers.h',

@ -108,7 +108,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gprpp/map.h ) s.files += %w( src/core/lib/gprpp/map.h )
s.files += %w( src/core/lib/gprpp/memory.h ) s.files += %w( src/core/lib/gprpp/memory.h )
s.files += %w( src/core/lib/gprpp/mpscq.h ) s.files += %w( src/core/lib/gprpp/mpscq.h )
s.files += %w( src/core/lib/gprpp/pair.h )
s.files += %w( src/core/lib/gprpp/sync.h ) s.files += %w( src/core/lib/gprpp/sync.h )
s.files += %w( src/core/lib/gprpp/thd.h ) s.files += %w( src/core/lib/gprpp/thd.h )
s.files += %w( src/core/lib/profiling/timers.h ) s.files += %w( src/core/lib/profiling/timers.h )

@ -113,7 +113,6 @@
<file baseinstalldir="/" name="src/core/lib/gprpp/map.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/map.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/memory.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/memory.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/mpscq.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/mpscq.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/pair.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/sync.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/sync.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/thd.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/gprpp/thd.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/profiling/timers.h" role="src" /> <file baseinstalldir="/" name="src/core/lib/profiling/timers.h" role="src" />

@ -407,7 +407,7 @@ class XdsLb : public LoadBalancingPolicy {
// proportional to the locality's weight. The start of the range is the // proportional to the locality's weight. The start of the range is the
// previous value in the vector and is 0 for the first element. // previous value in the vector and is 0 for the first element.
using PickerList = using PickerList =
InlinedVector<Pair<uint32_t, RefCountedPtr<PickerWrapper>>, 1>; InlinedVector<std::pair<uint32_t, RefCountedPtr<PickerWrapper>>, 1>;
Picker(RefCountedPtr<XdsLb> xds_policy, PickerList pickers) Picker(RefCountedPtr<XdsLb> xds_policy, PickerList pickers)
: xds_policy_(std::move(xds_policy)), : xds_policy_(std::move(xds_policy)),
pickers_(std::move(pickers)), pickers_(std::move(pickers)),
@ -2343,7 +2343,7 @@ void XdsLb::PriorityList::LocalityMap::UpdateXdsPickerLocked() {
if (!locality_map_update()->Contains(locality_name)) continue; if (!locality_map_update()->Contains(locality_name)) continue;
if (locality->connectivity_state() != GRPC_CHANNEL_READY) continue; if (locality->connectivity_state() != GRPC_CHANNEL_READY) continue;
end += locality->weight(); end += locality->weight();
picker_list.push_back(MakePair(end, locality->picker_wrapper())); picker_list.push_back(std::make_pair(end, locality->picker_wrapper()));
} }
xds_policy()->channel_control_helper()->UpdateState( xds_policy()->channel_control_helper()->UpdateState(
GRPC_CHANNEL_READY, GRPC_CHANNEL_READY,

@ -345,10 +345,11 @@ grpc_slice XdsLrsRequestCreateAndEncode(const char* server_name) {
namespace { namespace {
void LocalityStatsPopulate(envoy_api_v2_endpoint_UpstreamLocalityStats* output, void LocalityStatsPopulate(
Pair<const RefCountedPtr<XdsLocalityName>, envoy_api_v2_endpoint_UpstreamLocalityStats* output,
XdsClientStats::LocalityStats::Snapshot>& input, std::pair<const RefCountedPtr<XdsLocalityName>,
upb_arena* arena) { XdsClientStats::LocalityStats::Snapshot>& input,
upb_arena* arena) {
// Set sub_zone. // Set sub_zone.
envoy_api_v2_core_Locality* locality = envoy_api_v2_core_Locality* locality =
envoy_api_v2_endpoint_UpstreamLocalityStats_mutable_locality(output, envoy_api_v2_endpoint_UpstreamLocalityStats_mutable_locality(output,

@ -367,7 +367,7 @@ class Subchannel::ConnectedSubchannelStateWatcher
void Subchannel::ConnectivityStateWatcherList::AddWatcherLocked( void Subchannel::ConnectivityStateWatcherList::AddWatcherLocked(
OrphanablePtr<ConnectivityStateWatcherInterface> watcher) { OrphanablePtr<ConnectivityStateWatcherInterface> watcher) {
watchers_.insert(MakePair(watcher.get(), std::move(watcher))); watchers_.insert(std::make_pair(watcher.get(), std::move(watcher)));
} }
void Subchannel::ConnectivityStateWatcherList::RemoveWatcherLocked( void Subchannel::ConnectivityStateWatcherList::RemoveWatcherLocked(

@ -293,7 +293,7 @@ void ChannelNode::SetConnectivityState(grpc_connectivity_state state) {
void ChannelNode::AddChildChannel(intptr_t child_uuid) { void ChannelNode::AddChildChannel(intptr_t child_uuid) {
MutexLock lock(&child_mu_); MutexLock lock(&child_mu_);
child_channels_.insert(MakePair(child_uuid, true)); child_channels_.insert(std::make_pair(child_uuid, true));
} }
void ChannelNode::RemoveChildChannel(intptr_t child_uuid) { void ChannelNode::RemoveChildChannel(intptr_t child_uuid) {
@ -303,7 +303,7 @@ void ChannelNode::RemoveChildChannel(intptr_t child_uuid) {
void ChannelNode::AddChildSubchannel(intptr_t child_uuid) { void ChannelNode::AddChildSubchannel(intptr_t child_uuid) {
MutexLock lock(&child_mu_); MutexLock lock(&child_mu_);
child_subchannels_.insert(MakePair(child_uuid, true)); child_subchannels_.insert(std::make_pair(child_uuid, true));
} }
void ChannelNode::RemoveChildSubchannel(intptr_t child_uuid) { void ChannelNode::RemoveChildSubchannel(intptr_t child_uuid) {
@ -323,7 +323,7 @@ ServerNode::~ServerNode() {}
void ServerNode::AddChildSocket(RefCountedPtr<SocketNode> node) { void ServerNode::AddChildSocket(RefCountedPtr<SocketNode> node) {
MutexLock lock(&child_mu_); MutexLock lock(&child_mu_);
child_sockets_.insert(MakePair(node->uuid(), std::move(node))); child_sockets_.insert(std::make_pair(node->uuid(), std::move(node)));
} }
void ServerNode::RemoveChildSocket(intptr_t child_uuid) { void ServerNode::RemoveChildSocket(intptr_t child_uuid) {
@ -333,7 +333,7 @@ void ServerNode::RemoveChildSocket(intptr_t child_uuid) {
void ServerNode::AddChildListenSocket(RefCountedPtr<ListenSocketNode> node) { void ServerNode::AddChildListenSocket(RefCountedPtr<ListenSocketNode> node) {
MutexLock lock(&child_mu_); MutexLock lock(&child_mu_);
child_listen_sockets_.insert(MakePair(node->uuid(), std::move(node))); child_listen_sockets_.insert(std::make_pair(node->uuid(), std::move(node)));
} }
void ServerNode::RemoveChildListenSocket(intptr_t child_uuid) { void ServerNode::RemoveChildListenSocket(intptr_t child_uuid) {

@ -64,14 +64,14 @@ Arena* Arena::Create(size_t initial_size) {
return new (ArenaStorage(initial_size)) Arena(initial_size); return new (ArenaStorage(initial_size)) Arena(initial_size);
} }
Pair<Arena*, void*> Arena::CreateWithAlloc(size_t initial_size, std::pair<Arena*, void*> Arena::CreateWithAlloc(size_t initial_size,
size_t alloc_size) { size_t alloc_size) {
static constexpr size_t base_size = static constexpr size_t base_size =
GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(Arena)); GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(Arena));
auto* new_arena = auto* new_arena =
new (ArenaStorage(initial_size)) Arena(initial_size, alloc_size); new (ArenaStorage(initial_size)) Arena(initial_size, alloc_size);
void* first_alloc = reinterpret_cast<char*>(new_arena) + base_size; void* first_alloc = reinterpret_cast<char*>(new_arena) + base_size;
return MakePair(new_arena, first_alloc); return std::make_pair(new_arena, first_alloc);
} }
size_t Arena::Destroy() { size_t Arena::Destroy() {

@ -36,7 +36,6 @@
#include "src/core/lib/gpr/alloc.h" #include "src/core/lib/gpr/alloc.h"
#include "src/core/lib/gpr/spinlock.h" #include "src/core/lib/gpr/spinlock.h"
#include "src/core/lib/gprpp/atomic.h" #include "src/core/lib/gprpp/atomic.h"
#include "src/core/lib/gprpp/pair.h"
#include <stddef.h> #include <stddef.h>
@ -50,8 +49,8 @@ class Arena {
// Create an arena, with \a initial_size bytes in the first allocated buffer, // Create an arena, with \a initial_size bytes in the first allocated buffer,
// and return both a void pointer to the returned arena and a void* with the // and return both a void pointer to the returned arena and a void* with the
// first allocation. // first allocation.
static Pair<Arena*, void*> CreateWithAlloc(size_t initial_size, static std::pair<Arena*, void*> CreateWithAlloc(size_t initial_size,
size_t alloc_size); size_t alloc_size);
// Destroy an arena, returning the total number of bytes allocated. // Destroy an arena, returning the total number of bytes allocated.
size_t Destroy(); size_t Destroy();

@ -30,7 +30,6 @@
#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/pair.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/string_view.h" #include "src/core/lib/gprpp/string_view.h"

@ -1,38 +0,0 @@
/*
*
* Copyright 2017 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GRPC_CORE_LIB_GPRPP_PAIR_H
#define GRPC_CORE_LIB_GPRPP_PAIR_H
#include <grpc/support/port_platform.h>
#include <utility>
namespace grpc_core {
template <class T1, class T2>
using Pair = std::pair<T1, T2>;
template <class T1, class T2>
inline Pair<typename std::decay<T1>::type, typename std::decay<T2>::type>
MakePair(T1&& u, T2&& v) {
typedef typename std::decay<T1>::type V1;
typedef typename std::decay<T2>::type V2;
return Pair<V1, V2>(std::forward<T1>(u), std::forward<T2>(v));
}
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPRPP_PAIR_H */

@ -123,7 +123,7 @@ void ConnectivityStateTracker::AddWatcher(
// If we're in state SHUTDOWN, don't add the watcher, so that it will // If we're in state SHUTDOWN, don't add the watcher, so that it will
// be orphaned immediately. // be orphaned immediately.
if (current_state != GRPC_CHANNEL_SHUTDOWN) { if (current_state != GRPC_CHANNEL_SHUTDOWN) {
watchers_.insert(MakePair(watcher.get(), std::move(watcher))); watchers_.insert(std::make_pair(watcher.get(), std::move(watcher)));
} }
} }

@ -1117,7 +1117,6 @@ src/core/lib/gprpp/memory.h \
src/core/lib/gprpp/mpscq.h \ src/core/lib/gprpp/mpscq.h \
src/core/lib/gprpp/optional.h \ src/core/lib/gprpp/optional.h \
src/core/lib/gprpp/orphanable.h \ src/core/lib/gprpp/orphanable.h \
src/core/lib/gprpp/pair.h \
src/core/lib/gprpp/ref_counted.h \ src/core/lib/gprpp/ref_counted.h \
src/core/lib/gprpp/ref_counted_ptr.h \ src/core/lib/gprpp/ref_counted_ptr.h \
src/core/lib/gprpp/string_view.h \ src/core/lib/gprpp/string_view.h \

@ -1253,7 +1253,6 @@ src/core/lib/gprpp/mpscq.cc \
src/core/lib/gprpp/mpscq.h \ src/core/lib/gprpp/mpscq.h \
src/core/lib/gprpp/optional.h \ src/core/lib/gprpp/optional.h \
src/core/lib/gprpp/orphanable.h \ src/core/lib/gprpp/orphanable.h \
src/core/lib/gprpp/pair.h \
src/core/lib/gprpp/ref_counted.h \ src/core/lib/gprpp/ref_counted.h \
src/core/lib/gprpp/ref_counted_ptr.h \ src/core/lib/gprpp/ref_counted_ptr.h \
src/core/lib/gprpp/string_view.h \ src/core/lib/gprpp/string_view.h \

Loading…
Cancel
Save