From 28aaf25e651d274f1c52befdedf66b9768f415e8 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 25 Oct 2023 22:03:14 +0200 Subject: only measure a variable integer once where we can (#500) --- src/zencore/include/zencore/varint.h | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/zencore/include') diff --git a/src/zencore/include/zencore/varint.h b/src/zencore/include/zencore/varint.h index e57e1d497..c0d63d814 100644 --- a/src/zencore/include/zencore/varint.h +++ b/src/zencore/include/zencore/varint.h @@ -104,15 +104,12 @@ MeasureVarInt(int64_t InValue) * Read a variable-length unsigned integer. * * @param InData A variable-length encoding of an unsigned integer. - * @param OutByteCount The number of bytes consumed from the input. + * @param ByteCount The number of bytes to be consumed from the input. * @return An unsigned integer. */ inline uint64_t -ReadVarUInt(const void* InData, uint32_t& OutByteCount) +ReadMeasuredVarUInt(const void* InData, uint32_t ByteCount) { - const uint32_t ByteCount = MeasureVarUInt(InData); - OutByteCount = ByteCount; - const uint8_t* InBytes = static_cast(InData); uint64_t Value = *InBytes++ & uint8_t(0xff >> ByteCount); switch (ByteCount - 1) @@ -154,6 +151,21 @@ ReadVarUInt(const void* InData, uint32_t& OutByteCount) } } +/** + * Read a variable-length unsigned integer. + * + * @param InData A variable-length encoding of an unsigned integer. + * @param OutByteCount The number of bytes consumed from the input. + * @return An unsigned integer. + */ +inline uint64_t +ReadVarUInt(const void* InData, uint32_t& OutByteCount) +{ + const uint32_t ByteCount = MeasureVarUInt(InData); + OutByteCount = ByteCount; + return ReadMeasuredVarUInt(InData, ByteCount); +} + /** * Read a variable-length signed integer. * -- cgit v1.2.3