mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 12:08:20 +00:00
quic: Avoid bytes for VariableLengthInteger
Allocation of bytes objects due to parsing and usage of pack and the invocation of to_uint() showed significantly in profiles (3.3% sample matches). Switch to a more procedural approach to avoid the allocation overhead. From zeek/spicy-quic/pull/13
This commit is contained in:
parent
e33528ec5b
commit
994d66185c
1 changed files with 5 additions and 9 deletions
|
@ -140,17 +140,13 @@ type VariableLengthInteger = unit {
|
||||||
#
|
#
|
||||||
# https://datatracker.ietf.org/doc/rfc9000/
|
# https://datatracker.ietf.org/doc/rfc9000/
|
||||||
# Section 16 and Appendix A
|
# Section 16 and Appendix A
|
||||||
#
|
: uint8 {
|
||||||
first_byte: bytes &size=1 {
|
self.bytes_to_parse = 2**((0xC0 & $$) >> 6);
|
||||||
local uint8_val = uint8($$.to_uint(spicy::ByteOrder::Big));
|
self.result = $$ & 0x3F;
|
||||||
self.bytes_to_parse = 2**((0xC0 & uint8_val) >> 6);
|
|
||||||
# Re-pack without most significant two bits for later use.
|
|
||||||
self.first_byte = pack(0x3f & uint8_val, spicy::ByteOrder::Big);
|
|
||||||
}
|
}
|
||||||
remaining_bytes: bytes &size=self.bytes_to_parse - 1;
|
|
||||||
|
|
||||||
on %done {
|
: uint8[self.bytes_to_parse - 1] if (self.bytes_to_parse > 1) foreach {
|
||||||
self.result = (self.first_byte + self.remaining_bytes).to_uint(spicy::ByteOrder::Big);
|
self.result = (self.result << 8) | $$;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue