Skip to content

Commit

Permalink
improve encode_varint performance by bounding its loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mumbleskates committed Mar 8, 2024
1 parent a8e8c9d commit 561fa9c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub fn encode_varint<B>(mut value: u64, buf: &mut B)
where
B: BufMut,
{
loop {
// Varints are never more than 10 bytes
for _ in 0..10 {
if value < 0x80 {
buf.put_u8(value as u8);
break;
Expand Down

0 comments on commit 561fa9c

Please sign in to comment.