aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpliard@google.com <pliard@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2012-03-02 14:00:20 +0000
committerpliard@google.com <pliard@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2012-03-02 14:00:20 +0000
commit324779ad702fdef0cd3bd4e56ed0128ffaa6113e (patch)
treec8a36c5f235e24bf0eed78c4f1d4b31273db3273
parentf5de486b533e0f0a22d7a4b3606619dda65e294d (diff)
downloadprotobuf-324779ad702fdef0cd3bd4e56ed0128ffaa6113e.tar.gz
protobuf-324779ad702fdef0cd3bd4e56ed0128ffaa6113e.tar.bz2
protobuf-324779ad702fdef0cd3bd4e56ed0128ffaa6113e.zip
Remove static initializer in wire_format_lite.cc.
-rw-r--r--src/google/protobuf/io/coded_stream.h15
-rw-r--r--src/google/protobuf/wire_format_lite.cc8
2 files changed, 19 insertions, 4 deletions
diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h
index 1b6b4e18..97ac5079 100644
--- a/src/google/protobuf/io/coded_stream.h
+++ b/src/google/protobuf/io/coded_stream.h
@@ -680,6 +680,21 @@ class LIBPROTOBUF_EXPORT CodedOutputStream {
// If negative, 10 bytes. Otheriwse, same as VarintSize32().
static int VarintSize32SignExtended(int32 value);
+ // Compile-time equivalent of VarintSize32().
+ template <uint32 Value>
+ struct StaticVarintSize32 {
+ static const int value =
+ (Value < (1 << 7))
+ ? 1
+ : (Value < (1 << 14))
+ ? 2
+ : (Value < (1 << 21))
+ ? 3
+ : (Value < (1 << 28))
+ ? 4
+ : 5;
+ };
+
// Returns the total number of bytes written since this object was created.
inline int ByteCount() const;
diff --git a/src/google/protobuf/wire_format_lite.cc b/src/google/protobuf/wire_format_lite.cc
index d347d116..dbd29b47 100644
--- a/src/google/protobuf/wire_format_lite.cc
+++ b/src/google/protobuf/wire_format_lite.cc
@@ -56,10 +56,10 @@ const int WireFormatLite::kMessageSetMessageTag;
#endif
const int WireFormatLite::kMessageSetItemTagsSize =
- io::CodedOutputStream::VarintSize32(kMessageSetItemStartTag) +
- io::CodedOutputStream::VarintSize32(kMessageSetItemEndTag) +
- io::CodedOutputStream::VarintSize32(kMessageSetTypeIdTag) +
- io::CodedOutputStream::VarintSize32(kMessageSetMessageTag);
+ io::CodedOutputStream::StaticVarintSize32<kMessageSetItemStartTag>::value +
+ io::CodedOutputStream::StaticVarintSize32<kMessageSetItemEndTag>::value +
+ io::CodedOutputStream::StaticVarintSize32<kMessageSetTypeIdTag>::value +
+ io::CodedOutputStream::StaticVarintSize32<kMessageSetMessageTag>::value;
const WireFormatLite::CppType
WireFormatLite::kFieldTypeToCppTypeMap[MAX_FIELD_TYPE + 1] = {