mirror of
https://github.com/esphome/esphome.git
synced 2026-09-24 05:24:14 +00:00
[api] Add 2-byte inline fast path for sint32 varint encode/size
Add encode_varint_raw_short() and ProtoSize::varint_short() that inline both the 1-byte and 2-byte varint paths, falling back to the noinline slow path for 3+ bytes. Use these for sint32 fields (zigzag encoding), where values like RSSI (-100 to 0) produce zigzag values that are 1-2 bytes. This avoids a function call for the common case without bloating the generic encode_varint_raw fast path.
This commit is contained in:
@@ -229,7 +229,7 @@ class TypeInfo(ABC):
|
||||
RAW_ENCODE_MAP: dict[str, str] = {
|
||||
"encode_uint32": "buffer.encode_varint_raw({value});",
|
||||
"encode_uint64": "buffer.encode_varint_raw_64({value});",
|
||||
"encode_sint32": "buffer.encode_varint_raw(encode_zigzag32({value}));",
|
||||
"encode_sint32": "buffer.encode_varint_raw_short(encode_zigzag32({value}));",
|
||||
"encode_sint64": "buffer.encode_varint_raw_64(encode_zigzag64({value}));",
|
||||
"encode_int64": "buffer.encode_varint_raw_64(static_cast<uint64_t>({value}));",
|
||||
"encode_bool": "buffer.write_raw_byte({value} ? 0x01 : 0x00);",
|
||||
|
||||
Reference in New Issue
Block a user