Speed up writing protobuf strings/bytes (#5828)

This commit is contained in:
J. Nick Koston 2023-12-18 19:24:48 -10:00 committed by GitHub
parent 52b9668170
commit cd06dc77ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -160,8 +160,7 @@ class ProtoWriteBuffer {
this->encode_field_raw(field_id, 2); this->encode_field_raw(field_id, 2);
this->encode_varint_raw(len); this->encode_varint_raw(len);
auto *data = reinterpret_cast<const uint8_t *>(string); auto *data = reinterpret_cast<const uint8_t *>(string);
for (size_t i = 0; i < len; i++) this->buffer_->insert(this->buffer_->end(), data, data + len);
this->write(data[i]);
} }
void encode_string(uint32_t field_id, const std::string &value, bool force = false) { void encode_string(uint32_t field_id, const std::string &value, bool force = false) {
this->encode_string(field_id, value.data(), value.size()); this->encode_string(field_id, value.data(), value.size());