Stop generating method name array when there is no method.

pull/9406/head
yang-g 8 years ago
parent ada49f0978
commit 20115614e1
  1. 15
      src/compiler/cpp_generator.cc

@ -1218,13 +1218,15 @@ void PrintSourceService(Printer *printer, const Service *service,
std::map<grpc::string, grpc::string> *vars) { std::map<grpc::string, grpc::string> *vars) {
(*vars)["Service"] = service->name(); (*vars)["Service"] = service->name();
printer->Print(*vars, if (service->method_count() > 0) {
"static const char* $prefix$$Service$_method_names[] = {\n"); printer->Print(*vars,
for (int i = 0; i < service->method_count(); ++i) { "static const char* $prefix$$Service$_method_names[] = {\n");
(*vars)["Method"] = service->method(i).get()->name(); for (int i = 0; i < service->method_count(); ++i) {
printer->Print(*vars, " \"/$Package$$Service$/$Method$\",\n"); (*vars)["Method"] = service->method(i).get()->name();
printer->Print(*vars, " \"/$Package$$Service$/$Method$\",\n");
}
printer->Print(*vars, "};\n\n");
} }
printer->Print(*vars, "};\n\n");
printer->Print(*vars, printer->Print(*vars,
"std::unique_ptr< $ns$$Service$::Stub> $ns$$Service$::NewStub(" "std::unique_ptr< $ns$$Service$::Stub> $ns$$Service$::NewStub("
@ -1272,7 +1274,6 @@ void PrintSourceService(Printer *printer, const Service *service,
printer->Print(*vars, "$ns$$Service$::Service::Service() {\n"); printer->Print(*vars, "$ns$$Service$::Service::Service() {\n");
printer->Indent(); printer->Indent();
printer->Print(*vars, "(void)$prefix$$Service$_method_names;\n");
for (int i = 0; i < service->method_count(); ++i) { for (int i = 0; i < service->method_count(); ++i) {
auto method = service->method(i); auto method = service->method(i);
(*vars)["Idx"] = as_string(i); (*vars)["Idx"] = as_string(i);

Loading…
Cancel
Save