mirror of
https://github.com/esphome/esphome.git
synced 2026-07-11 01:15:33 +00:00
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:
@@ -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()",
|
||||
|
||||
Reference in New Issue
Block a user