From 4da3dd89bbb12c4992e64d0af992c7c306363230 Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Sat, 27 Feb 2021 17:57:30 +0100 Subject: [PATCH] [C++] Delete StringPiecePod Protobuf no longer supports C++ < 11, so this type is no longer required. --- src/google/protobuf/stubs/stringpiece.h | 43 ------------------- src/google/protobuf/stubs/strutil.h | 3 -- src/google/protobuf/util/internal/datapiece.h | 8 ++-- 3 files changed, 3 insertions(+), 51 deletions(-) diff --git a/src/google/protobuf/stubs/stringpiece.h b/src/google/protobuf/stubs/stringpiece.h index fbcb20afc41..0a426fec34b 100644 --- a/src/google/protobuf/stubs/stringpiece.h +++ b/src/google/protobuf/stubs/stringpiece.h @@ -426,49 +426,6 @@ inline bool operator>=(StringPiece x, StringPiece y) { // allow StringPiece to be logged extern std::ostream& operator<<(std::ostream& o, StringPiece piece); -namespace internal { -// StringPiece is not a POD and can not be used in an union (pre C++11). We -// need a POD version of it. -struct StringPiecePod { - // Create from a StringPiece. - static StringPiecePod CreateFromStringPiece(StringPiece str) { - StringPiecePod pod; - pod.data_ = str.data(); - pod.size_ = str.size(); - return pod; - } - - // Cast to StringPiece. - operator StringPiece() const { return StringPiece(data_, size_); } - - bool operator==(const char* value) const { - return StringPiece(data_, size_) == StringPiece(value); - } - - char operator[](stringpiece_ssize_type i) const { - assert(0 <= i); - assert(i < size_); - return data_[i]; - } - - const char* data() const { return data_; } - - stringpiece_ssize_type size() const { - return size_; - } - - std::string ToString() const { - return std::string(data_, static_cast(size_)); - } - - explicit operator std::string() const { return ToString(); } - - private: - const char* data_; - stringpiece_ssize_type size_; -}; - -} // namespace internal } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/stubs/strutil.h b/src/google/protobuf/stubs/strutil.h index 8ce81f28c39..31c548982ec 100644 --- a/src/google/protobuf/stubs/strutil.h +++ b/src/google/protobuf/stubs/strutil.h @@ -664,9 +664,6 @@ struct PROTOBUF_EXPORT AlphaNum { AlphaNum(StringPiece str) : piece_data_(str.data()), piece_size_(str.size()) {} - AlphaNum(internal::StringPiecePod str) - : piece_data_(str.data()), piece_size_(str.size()) {} - size_t size() const { return piece_size_; } const char *data() const { return piece_data_; } diff --git a/src/google/protobuf/util/internal/datapiece.h b/src/google/protobuf/util/internal/datapiece.h index 03ea128bdbc..a8fe7174572 100644 --- a/src/google/protobuf/util/internal/datapiece.h +++ b/src/google/protobuf/util/internal/datapiece.h @@ -93,12 +93,12 @@ class PROTOBUF_EXPORT DataPiece { : type_(TYPE_BOOL), bool_(value), use_strict_base64_decoding_(false) {} DataPiece(StringPiece value, bool use_strict_base64_decoding) : type_(TYPE_STRING), - str_(StringPiecePod::CreateFromStringPiece(value)), + str_(value), use_strict_base64_decoding_(use_strict_base64_decoding) {} // Constructor for bytes. The second parameter is not used. DataPiece(StringPiece value, bool dummy, bool use_strict_base64_decoding) : type_(TYPE_BYTES), - str_(StringPiecePod::CreateFromStringPiece(value)), + str_(value), use_strict_base64_decoding_(use_strict_base64_decoding) {} DataPiece(const DataPiece& r) : type_(r.type_) { InternalCopy(r); } @@ -191,8 +191,6 @@ class PROTOBUF_EXPORT DataPiece { // Data type for this piece of data. Type type_; - typedef ::google::protobuf::internal::StringPiecePod StringPiecePod; - // Stored piece of data. union { int32 i32_; @@ -202,7 +200,7 @@ class PROTOBUF_EXPORT DataPiece { double double_; float float_; bool bool_; - StringPiecePod str_; + StringPiece str_; }; // Uses a stricter version of base64 decoding for byte fields.