From 561fa9c07852e4195e88c63dc0ad31112f7ae1c6 Mon Sep 17 00:00:00 2001 From: Kent Ross Date: Sun, 12 Nov 2023 19:35:58 -0800 Subject: [PATCH] improve encode_varint performance by bounding its loop --- src/encoding.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/encoding.rs b/src/encoding.rs index 0c77123c5..789bb3941 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -27,7 +27,8 @@ pub fn encode_varint(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;