mirror of
https://github.com/esphome/esphome.git
synced 2025-08-01 16:07:47 +00:00
encode perf
This commit is contained in:
parent
9e78b5b06f
commit
ac64dbfb8d
@ -176,6 +176,18 @@ class ProtoVarInt {
|
|||||||
out.push_back(val);
|
out.push_back(val);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Optimize for 2-byte varints (0x80-0x3FFF)
|
||||||
|
if (val <= 0x3FFF) {
|
||||||
|
out.push_back((val & 0x7F) | 0x80);
|
||||||
|
out.push_back(val >> 7);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// For 3+ byte varints, write first 2 bytes directly
|
||||||
|
out.push_back((val & 0x7F) | 0x80);
|
||||||
|
out.push_back(((val >> 7) & 0x7F) | 0x80);
|
||||||
|
val >>= 14;
|
||||||
|
|
||||||
|
// Continue with remaining bytes
|
||||||
while (val) {
|
while (val) {
|
||||||
uint8_t temp = val & 0x7F;
|
uint8_t temp = val & 0x7F;
|
||||||
val >>= 7;
|
val >>= 7;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user