Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1760)

Unified Diff: third_party/protobuf/src/google/protobuf/generated_message_util.h

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/protobuf/src/google/protobuf/generated_message_util.h
diff --git a/third_party/protobuf/src/google/protobuf/generated_message_util.h b/third_party/protobuf/src/google/protobuf/generated_message_util.h
index 36f18da940b3831808941118c5156a2353d7a0bc..4b03222f922241c9f2717e189aba6088b3451cee 100644
--- a/third_party/protobuf/src/google/protobuf/generated_message_util.h
+++ b/third_party/protobuf/src/google/protobuf/generated_message_util.h
@@ -41,8 +41,17 @@
#include <assert.h>
#include <string>
-#include <google/protobuf/stubs/once.h>
#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/once.h>
+#include <google/protobuf/has_bits.h>
+
+#ifndef PROTOBUF_FINAL
+#if __cplusplus >= 201103L
+#define PROTOBUF_FINAL final
+#else
+#define PROTOBUF_FINAL
+#endif
+#endif // !PROTOBUF_FINAL
namespace google {
@@ -63,30 +72,69 @@ namespace internal {
#undef DEPRECATED_PROTOBUF_FIELD
#define PROTOBUF_DEPRECATED
-#define PROTOBUF_DEPRECATED_ATTR
+#define GOOGLE_PROTOBUF_DEPRECATED_ATTR
// Constants for special floating point values.
LIBPROTOBUF_EXPORT double Infinity();
LIBPROTOBUF_EXPORT double NaN();
+// This type is used to define a global variable, without it's constructor
+// and destructor run on start and end of the program lifetime. This circumvents
+// the initial construction order fiasco, while keeping the address of the
+// empty string a compile time constant.
+template <typename T>
+class ExplicitlyConstructed {
+ public:
+ void DefaultConstruct() {
+ new (&union_) T();
+ init_ = true;
+ }
+
+ bool IsInitialized() { return init_; }
+ void Shutdown() {
+ if (init_) {
+ init_ = false;
+ get_mutable()->~T();
+ }
+ }
+
+#if __cplusplus >= 201103L
+ constexpr
+#endif
+ const T&
+ get() const {
+ return reinterpret_cast<const T&>(union_);
+ }
+ T* get_mutable() { return reinterpret_cast<T*>(&union_); }
+
+ private:
+ // Prefer c++14 aligned_storage, but for compatibility this will do.
+ union AlignedUnion {
+ char space[sizeof(T)];
+ int64 align_to_int64;
+ void* align_to_ptr;
+ } union_;
+ bool init_; // false by linker
+};
+
// TODO(jieluo): Change to template. We have tried to use template,
// but it causes net/rpc/python:rpcutil_test fail (the empty string will
// init twice). It may related to swig. Change to template after we
// found the solution.
-// Default empty string object. Don't use the pointer directly. Instead, call
+// Default empty string object. Don't use this directly. Instead, call
// GetEmptyString() to get the reference.
-LIBPROTOBUF_EXPORT extern const ::std::string* empty_string_;
+LIBPROTOBUF_EXPORT extern ExplicitlyConstructed< ::std::string> fixed_address_empty_string;
LIBPROTOBUF_EXPORT extern ProtobufOnceType empty_string_once_init_;
LIBPROTOBUF_EXPORT void InitEmptyString();
LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyStringAlreadyInited() {
- assert(empty_string_ != NULL);
- return *empty_string_;
+ return fixed_address_empty_string.get();
}
+
LIBPROTOBUF_EXPORT const ::std::string& GetEmptyString();
LIBPROTOBUF_EXPORT int StringSpaceUsedExcludingSelf(const string& str);
@@ -104,14 +152,25 @@ template <class Type> bool AllAreInitialized(const Type& t) {
return true;
}
-class ArenaString;
+LIBPROTOBUF_EXPORT void InitProtobufDefaults();
-// Read a length (varint32), followed by a string, from *input. Return a
-// pointer to a copy of the string that resides in *arena. Requires both
-// args to be non-NULL. If something goes wrong while reading the data
-// then NULL is returned (e.g., input does not start with a valid varint).
-ArenaString* ReadArenaString(::google::protobuf::io::CodedInputStream* input,
- ::google::protobuf::Arena* arena);
+// We compute sizes as size_t but cache them as int. This function converts a
+// computed size to a cached size. Since we don't proceed with serialization if
+// the total size was > INT_MAX, it is not important what this function returns
+// for inputs > INT_MAX.
+inline int ToCachedSize(size_t size) {
+ return static_cast<int>(size);
+}
+
+// We mainly calculate sizes in terms of size_t, but some functions that compute
+// sizes return "int". These int sizes are expected to always be positive.
+// This function is more efficient than casting an int to size_t directly on
+// 64-bit platforms because it avoids making the compiler emit a sign extending
+// instruction, which we don't want and don't want to pay for.
+inline size_t FromIntSize(int size) {
+ // Convert to unsigned before widening so sign extension is not necessary.
+ return static_cast<unsigned int>(size);
+}
} // namespace internal
} // namespace protobuf

Powered by Google App Engine
This is Rietveld 408576698