[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:
J. Nick Koston
2026-03-28 19:45:49 -10:00
parent 3886751662
commit 83e4478bc2
+6 -4
View File
@@ -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) {