aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/cpp/cpp_helpers.h
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_helpers.h
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_helpers.h')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_helpers.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h
index b13d53be..662a7c31 100644
--- a/src/google/protobuf/compiler/cpp/cpp_helpers.h
+++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h
@@ -35,12 +35,18 @@
#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__
#define GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__
+#include <map>
#include <string>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
namespace google {
namespace protobuf {
+
+namespace io {
+class Printer;
+}
+
namespace compiler {
namespace cpp {
@@ -150,6 +156,22 @@ inline bool HasFastArraySerialization(const FileDescriptor* file) {
return file->options().optimize_for() == FileOptions::SPEED;
}
+// Returns whether we have to generate code with static initializers.
+bool StaticInitializersForced(const FileDescriptor* file);
+
+// Prints 'with_static_init' if static initializers have to be used for the
+// provided file. Otherwise emits both 'with_static_init' and
+// 'without_static_init' using #ifdef.
+void PrintHandlingOptionalStaticInitializers(
+ const FileDescriptor* file, io::Printer* printer,
+ const char* with_static_init, const char* without_static_init,
+ const char* var1 = NULL, const string& val1 = "",
+ const char* var2 = NULL, const string& val2 = "");
+
+void PrintHandlingOptionalStaticInitializers(
+ const map<string, string>& vars, const FileDescriptor* file,
+ io::Printer* printer, const char* with_static_init,
+ const char* without_static_init);
} // namespace cpp
} // namespace compiler