Remove smart pointers from global registry

reviewable/pr18586/r2
Yash Tibrewal 6 years ago
parent 9bfd2354ec
commit 0c8ef41a5e
  1. 6
      src/core/ext/filters/client_channel/service_config.cc
  2. 13
      src/core/ext/filters/client_channel/service_config.h

@ -34,7 +34,7 @@
namespace grpc_core { namespace grpc_core {
int ServiceConfig::registered_parsers_count = 0; int ServiceConfig::registered_parsers_count = 0;
UniquePtr<ServiceConfigParser> ServiceConfigParser
ServiceConfig::registered_parsers[ServiceConfigParser::kMaxParsers]; ServiceConfig::registered_parsers[ServiceConfigParser::kMaxParsers];
RefCountedPtr<ServiceConfig> ServiceConfig::Create(const char* json) { RefCountedPtr<ServiceConfig> ServiceConfig::Create(const char* json) {
@ -85,7 +85,7 @@ void ServiceConfig::ParseGlobalParams(const grpc_json* json_tree,
GPR_DEBUG_ASSERT(json_tree_->key == nullptr); GPR_DEBUG_ASSERT(json_tree_->key == nullptr);
for (auto i = 0; i < registered_parsers_count; i++) { for (auto i = 0; i < registered_parsers_count; i++) {
auto parsed_obj = auto parsed_obj =
registered_parsers[i]->ParseGlobalParams(json_tree, success); registered_parsers[i].ParseGlobalParams(json_tree, success);
if (!*success) { if (!*success) {
return; return;
} }
@ -102,7 +102,7 @@ bool ServiceConfig::ParseJsonMethodConfigToServiceConfigObjectsTable(
for (auto i = 0; i < registered_parsers_count; i++) { for (auto i = 0; i < registered_parsers_count; i++) {
bool success; bool success;
auto parsed_obj = auto parsed_obj =
registered_parsers[i]->ParsePerMethodParams(json, &success); registered_parsers[i].ParsePerMethodParams(json, &success);
if (!success) { if (!success) {
return false; return false;
} }

@ -176,17 +176,12 @@ class ServiceConfig : public RefCounted<ServiceConfig> {
/// registered parser. Each parser is responsible for reading the service /// registered parser. Each parser is responsible for reading the service
/// config json and returning a parsed object. This parsed object can later be /// config json and returning a parsed object. This parsed object can later be
/// retrieved using the same index that was returned at registration time. /// retrieved using the same index that was returned at registration time.
static int RegisterParser(UniquePtr<ServiceConfigParser> func) { static int RegisterParser(const ServiceConfigParser& parser) {
registered_parsers[registered_parsers_count] = std::move(func); registered_parsers[registered_parsers_count] = parser;
return registered_parsers_count++; return registered_parsers_count++;
} }
static void ResetServiceConfigParsers() { static void ResetServiceConfigParsers() { registered_parsers_count = 0; }
for (auto i = 0; i < ServiceConfigParser::kMaxParsers; i++) {
registered_parsers[i].reset(nullptr);
}
registered_parsers_count = 0;
}
private: private:
// So New() can call our private ctor. // So New() can call our private ctor.
@ -222,7 +217,7 @@ class ServiceConfig : public RefCounted<ServiceConfig> {
size_t* idx); size_t* idx);
static int registered_parsers_count; static int registered_parsers_count;
static UniquePtr<ServiceConfigParser> static ServiceConfigParser
registered_parsers[ServiceConfigParser::kMaxParsers]; registered_parsers[ServiceConfigParser::kMaxParsers];
UniquePtr<char> service_config_json_; UniquePtr<char> service_config_json_;

Loading…
Cancel
Save