Move StringSpaceUsedIncludingSelf to lite library. This came up because Chromium downstream modifies the lite library in a way that requires this function, but I'm upstreaming it because based on the comments in repeated_field.h, this ought to allow resolution of an existing hack. I don't know enough about the protobuf code to feel confident trying to resolve this hack myself, so I've merely updated the TODO comments.
diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 412c48a..0b01e73 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc
@@ -57,18 +57,6 @@ } } // anonymous namespace -int StringSpaceUsedExcludingSelf(const string& str) { - const void* start = &str; - const void* end = &str + 1; - - if (start <= str.data() && str.data() < end) { - // The string's data is stored inside the string object itself. - return 0; - } else { - return str.capacity(); - } -} - bool ParseNamedEnum(const EnumDescriptor* descriptor, const string& name, int* value) {
diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc index 53cae8b..afaca2e 100644 --- a/src/google/protobuf/generated_message_util.cc +++ b/src/google/protobuf/generated_message_util.cc
@@ -60,6 +60,18 @@ OnShutdown(&DeleteEmptyString); } +int StringSpaceUsedExcludingSelf(const string& str) { + const void* start = &str; + const void* end = &str + 1; + + if (start <= str.data() && str.data() < end) { + // The string's data is stored inside the string object itself. + return 0; + } else { + return str.capacity(); + } +} + } // namespace internal } // namespace protobuf
diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index 6357e27..78c8d7f 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h
@@ -89,12 +89,6 @@ return GetEmptyStringAlreadyInited(); } -// Defined in generated_message_reflection.cc -- not actually part of the lite -// library. -// -// TODO(jasonh): The various callers get this declaration from a variety of -// places: probably in most cases repeated_field.h. Clean these up so they all -// get the declaration from this file. LIBPROTOBUF_EXPORT int StringSpaceUsedExcludingSelf(const string& str);
diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 9c84ed9..2ba5dfd 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h
@@ -647,7 +647,8 @@ // StringTypeHandler is exported. So, we factor out StringTypeHandlerBase, // export that, then make StringTypeHandler be a subclass which is NOT // exported. -// TODO(kenton): There has to be a better way. +// TODO(kenton): Now that StringSpaceUsedExcludingSelf() is in the lite +// library, this can be cleaned up. class LIBPROTOBUF_EXPORT StringTypeHandlerBase { public: typedef string Type;