From 20115614e1ebbdfb8a3711d425f6edd6cd964734 Mon Sep 17 00:00:00 2001 From: yang-g Date: Thu, 19 Jan 2017 10:57:56 -0800 Subject: Stop generating method name array when there is no method. --- src/compiler/cpp_generator.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index a26eeb46b9..e481aaf811 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -1218,13 +1218,15 @@ void PrintSourceService(Printer *printer, const Service *service, std::map *vars) { (*vars)["Service"] = service->name(); - printer->Print(*vars, - "static const char* $prefix$$Service$_method_names[] = {\n"); - for (int i = 0; i < service->method_count(); ++i) { - (*vars)["Method"] = service->method(i).get()->name(); - printer->Print(*vars, " \"/$Package$$Service$/$Method$\",\n"); + if (service->method_count() > 0) { + printer->Print(*vars, + "static const char* $prefix$$Service$_method_names[] = {\n"); + for (int i = 0; i < service->method_count(); ++i) { + (*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, "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->Indent(); - printer->Print(*vars, "(void)$prefix$$Service$_method_names;\n"); for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); (*vars)["Idx"] = as_string(i); -- cgit v1.2.3