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

Migrate coded output stream arguments from const std::string& to absl::string_view. #19561

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/google/protobuf/io/coded_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -986,25 +986,17 @@ uint8_t* EpsCopyOutputStream::WriteCord(const absl::Cord& cord, uint8_t* ptr) {
}
}

uint8_t* EpsCopyOutputStream::WriteStringMaybeAliasedOutline(uint32_t num,
const std::string& s,
uint8_t* ptr) {
uint8_t* EpsCopyOutputStream::WriteStringMaybeAliasedOutline(
uint32_t num, absl::string_view s, uint8_t* ptr) {
ptr = EnsureSpace(ptr);
uint32_t size = s.size();
ptr = WriteLengthDelim(num, size, ptr);
return WriteRawMaybeAliased(s.data(), size, ptr);
}

uint8_t* EpsCopyOutputStream::WriteStringOutline(uint32_t num, const std::string& s,
uint8_t* ptr) {
ptr = EnsureSpace(ptr);
uint32_t size = s.size();
ptr = WriteLengthDelim(num, size, ptr);
return WriteRaw(s.data(), size, ptr);
}

uint8_t* EpsCopyOutputStream::WriteStringOutline(uint32_t num, absl::string_view s,
uint8_t* ptr) {
uint8_t* EpsCopyOutputStream::WriteStringOutline(uint32_t num,
absl::string_view s,
uint8_t* ptr) {
ptr = EnsureSpace(ptr);
uint32_t size = s.size();
ptr = WriteLengthDelim(num, size, ptr);
Expand All @@ -1028,8 +1020,8 @@ uint8_t* CodedOutputStream::WriteCordToArray(const absl::Cord& cord,
}


uint8_t* CodedOutputStream::WriteStringWithSizeToArray(const std::string& str,
uint8_t* target) {
uint8_t* CodedOutputStream::WriteStringWithSizeToArray(absl::string_view str,
uint8_t* target) {
ABSL_DCHECK_LE(str.size(), std::numeric_limits<uint32_t>::max());
target = WriteVarint32ToArray(str.size(), target);
return WriteStringToArray(str, target);
Expand Down
17 changes: 8 additions & 9 deletions src/google/protobuf/io/coded_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ class PROTOBUF_EXPORT EpsCopyOutputStream {
#ifndef NDEBUG
PROTOBUF_NOINLINE
#endif
uint8_t* WriteStringMaybeAliased(uint32_t num, const std::string& s,
uint8_t* WriteStringMaybeAliased(uint32_t num, absl::string_view s,
uint8_t* ptr) {
std::ptrdiff_t size = s.size();
if (ABSL_PREDICT_FALSE(size >= 128 ||
Expand All @@ -705,7 +705,7 @@ class PROTOBUF_EXPORT EpsCopyOutputStream {
std::memcpy(ptr, s.data(), size);
return ptr + size;
}
uint8_t* WriteBytesMaybeAliased(uint32_t num, const std::string& s,
uint8_t* WriteBytesMaybeAliased(uint32_t num, absl::string_view s,
uint8_t* ptr) {
return WriteStringMaybeAliased(num, s, ptr);
}
Expand Down Expand Up @@ -864,9 +864,8 @@ class PROTOBUF_EXPORT EpsCopyOutputStream {

uint8_t* WriteAliasedRaw(const void* data, int size, uint8_t* ptr);

uint8_t* WriteStringMaybeAliasedOutline(uint32_t num, const std::string& s,
uint8_t* WriteStringMaybeAliasedOutline(uint32_t num, absl::string_view s,
uint8_t* ptr);
uint8_t* WriteStringOutline(uint32_t num, const std::string& s, uint8_t* ptr);
uint8_t* WriteStringOutline(uint32_t num, absl::string_view s, uint8_t* ptr);
uint8_t* WriteCordOutline(const absl::Cord& c, uint8_t* ptr);

Expand Down Expand Up @@ -1117,11 +1116,11 @@ class PROTOBUF_EXPORT CodedOutputStream {
uint8_t* target);

// Equivalent to WriteRaw(str.data(), str.size()).
void WriteString(const std::string& str);
void WriteString(absl::string_view str);
// Like WriteString() but writing directly to the target array.
static uint8_t* WriteStringToArray(const std::string& str, uint8_t* target);
static uint8_t* WriteStringToArray(absl::string_view str, uint8_t* target);
// Write the varint-encoded size of str followed by str.
static uint8_t* WriteStringWithSizeToArray(const std::string& str,
static uint8_t* WriteStringWithSizeToArray(absl::string_view str,
uint8_t* target);

// Like WriteString() but writes a Cord.
Expand Down Expand Up @@ -1790,7 +1789,7 @@ inline size_t CodedOutputStream::VarintSize32SignExtendedPlusOne(
}
#undef PROTOBUF_CODED_STREAM_H_PREFER_BSR

inline void CodedOutputStream::WriteString(const std::string& str) {
inline void CodedOutputStream::WriteString(absl::string_view str) {
WriteRaw(str.data(), static_cast<int>(str.size()));
}

Expand All @@ -1805,7 +1804,7 @@ inline uint8_t* CodedOutputStream::WriteRawToArray(const void* data, int size,
return target + size;
}

inline uint8_t* CodedOutputStream::WriteStringToArray(const std::string& str,
inline uint8_t* CodedOutputStream::WriteStringToArray(absl::string_view str,
uint8_t* target) {
return WriteRawToArray(str.data(), static_cast<int>(str.size()), target);
}
Expand Down
Loading