Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] Delete StringPiecePod #8353

Merged
merged 1 commit into from Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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