Commit f0640b5a authored by Feng Xiao's avatar Feng Xiao

Merge pull request #770 from pkasting/string_space

Move StringSpaceUsedIncludingSelf to lite library.
parents 69ac02a2 b913cbd3
......@@ -57,18 +57,6 @@ bool IsMapFieldInApi(const FieldDescriptor* field) {
}
} // 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) {
......
......@@ -60,6 +60,18 @@ void InitEmptyString() {
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
......
......@@ -89,12 +89,6 @@ LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyString() {
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);
......
......@@ -647,7 +647,8 @@ inline const Message& GenericTypeHandler<Message>::default_instance() {
// 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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment