mirror of
https://github.com/esphome/esphome.git
synced 2026-09-16 09:38:42 +00:00
[api] Apply __restrict__ local hoist to encode_varint_raw_slow_
Same optimization as encode_varint_raw_64: hoist pos_ into a __restrict__ local so the compiler keeps it in a register across the loop instead of reloading from memory each iteration.
This commit is contained in:
@@ -11,13 +11,15 @@ static const char *const TAG = "api.proto";
|
||||
uint32_t ProtoSize::varint_slow(uint32_t value) { return varint_wide(value); }
|
||||
|
||||
void ProtoWriteBuffer::encode_varint_raw_slow_(uint32_t value) {
|
||||
// Use __restrict__ so the compiler knows pos doesn't alias this->
|
||||
// and can keep it in a register across the loop.
|
||||
uint8_t *__restrict__ pos = this->pos_;
|
||||
do {
|
||||
this->debug_check_bounds_(1);
|
||||
*this->pos_++ = static_cast<uint8_t>(value | 0x80);
|
||||
*pos++ = static_cast<uint8_t>(value | 0x80);
|
||||
value >>= 7;
|
||||
} while (value > 0x7F);
|
||||
this->debug_check_bounds_(1);
|
||||
*this->pos_++ = static_cast<uint8_t>(value);
|
||||
*pos++ = static_cast<uint8_t>(value);
|
||||
this->pos_ = pos;
|
||||
}
|
||||
|
||||
ProtoVarIntResult ProtoVarInt::parse_slow(const uint8_t *buffer, uint32_t len) {
|
||||
|
||||
Reference in New Issue
Block a user