Skip to content

Commit

Permalink
[C++] Delete StringPiecePod (#8353)
Browse files Browse the repository at this point in the history
Protobuf no longer supports C++ < 11, so this type is no longer
required.
  • Loading branch information
Yannic committed Mar 2, 2021
1 parent e9091e6 commit 88367af
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 51 deletions.
43 changes: 0 additions & 43 deletions src/google/protobuf/stubs/stringpiece.h
Expand Up @@ -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_t>(size_));
}

explicit operator std::string() const { return ToString(); }

private:
const char* data_;
stringpiece_ssize_type size_;
};

} // namespace internal
} // namespace protobuf
} // namespace google

Expand Down
3 changes: 0 additions & 3 deletions src/google/protobuf/stubs/strutil.h
Expand Up @@ -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_; }

Expand Down
8 changes: 3 additions & 5 deletions src/google/protobuf/util/internal/datapiece.h
Expand Up @@ -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); }
Expand Down Expand Up @@ -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_;
Expand All @@ -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.
Expand Down

0 comments on commit 88367af

Please sign in to comment.