Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify varint encoding #2645

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/runes/varint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,12 @@ pub fn encode_to_vec(mut n: u128, v: &mut Vec<u8>) {
let mut out = [0; 19];
let mut i = 18;

loop {
let mut byte = n.to_le_bytes()[0] & 0b0111_1111;

if i < 18 {
byte |= 0b1000_0000;
}

out[i] = byte;

if n < 0b1000_0000 {
break;
}
out[i] = n.to_le_bytes()[0] & 0b0111_1111;

while n > 0b0111_1111 {
n = n / 128 - 1;
i -= 1;
out[i] = n.to_le_bytes()[0] | 0b1000_0000;
}

v.extend_from_slice(&out[i..]);
Expand Down
Loading