Revert write_short_string for non-forced strings

Inlining the empty check + write_short_string for every non-forced
string field doubles code size vs a single encode_string call.
This commit is contained in:
J. Nick Koston
2026-04-06 08:49:37 -10:00
parent 4099064207
commit b8981aae12
2 changed files with 38 additions and 77 deletions
+2 -5
View File
@@ -1088,13 +1088,10 @@ class PointerToStringBufferType(PointerToBufferTypeBase):
@property
def encode_content(self) -> str:
max_len = self.max_data_length
if max_len is not None and max_len < 128:
if max_len is not None and max_len < 128 and self.force:
tag = self.calculate_tag()
if tag < 128:
call = f"ProtoEncode::write_short_string(pos PROTO_ENCODE_DEBUG_ARG, {tag}, this->{self.field_name});"
if self.force:
return call
return f"if (!this->{self.field_name}.empty())\n {call}"
return f"ProtoEncode::write_short_string(pos PROTO_ENCODE_DEBUG_ARG, {tag}, this->{self.field_name});"
if result := self._encode_bytes_with_precomputed_tag(
f"this->{self.field_name}.c_str()",
f"this->{self.field_name}.size()",