aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/cpp/cpp_message_field.cc
diff options
context:
space:
mode:
authorGravatar pliard@google.com <pliard@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2012-05-04 11:16:09 +0000
committerGravatar pliard@google.com <pliard@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2012-05-04 11:16:09 +0000
commit6103d4ed13d21e96cb0989fa7d38d83061da0281 (patch)
treedfe5fe88dec063622df889e208e3081ed7ac49e0 /src/google/protobuf/compiler/cpp/cpp_message_field.cc
parent7cc257673c5019b65dd04b55c21967b88b1d63c2 (diff)
Don't call AddDesc() at static init time in LITE_RUNTIME mode.
This patch makes the generation of StaticDescriptorInitializer_$filename$ depend on whether LITE_RUNTIME is enabled. Note that this works only when extensions are not used. This lets us significantly decrease the number of static initializers generated by protoc in LITE_RUNTIME mode (used in Chromium). In LITE_RUNTIME mode, $adddescriptorsname$() is called the first time that default_instance() is called (rather than being called during static init). To benefit from this patch in LITE_RUNTIME mode without extensions, compile with -DGOOGLE_PROTOBUF_NO_STATIC_INIT. BUG=351
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_message_field.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_message_field.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/src/google/protobuf/compiler/cpp/cpp_message_field.cc
index 23e75b87..7c785e7e 100644
--- a/src/google/protobuf/compiler/cpp/cpp_message_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_message_field.cc
@@ -82,8 +82,16 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
void MessageFieldGenerator::
GenerateInlineAccessorDefinitions(io::Printer* printer) const {
printer->Print(variables_,
- "inline const $type$& $classname$::$name$() const {\n"
- " return $name$_ != NULL ? *$name$_ : *default_instance_->$name$_;\n"
+ "inline const $type$& $classname$::$name$() const {\n");
+
+ PrintHandlingOptionalStaticInitializers(
+ variables_, descriptor_->file(), printer,
+ // With static initializers.
+ " return $name$_ != NULL ? *$name$_ : *default_instance_->$name$_;\n",
+ // Without.
+ " return $name$_ != NULL ? *$name$_ : *default_instance().$name$_;\n");
+
+ printer->Print(variables_,
"}\n"
"inline $type$* $classname$::mutable_$name$() {\n"
" set_has_$name$();\n"