aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/include
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-10-25 22:03:14 +0200
committerGitHub <[email protected]>2023-10-25 22:03:14 +0200
commit28aaf25e651d274f1c52befdedf66b9768f415e8 (patch)
treec117a285018344de06b323dca9e1fbc6f90084fa /src/zencore/include
parent0.2.29-pre0 (diff)
downloadzen-28aaf25e651d274f1c52befdedf66b9768f415e8.tar.xz
zen-28aaf25e651d274f1c52befdedf66b9768f415e8.zip
only measure a variable integer once where we can (#500)
Diffstat (limited to 'src/zencore/include')
-rw-r--r--src/zencore/include/zencore/varint.h22
1 files changed, 17 insertions, 5 deletions
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<const uint8_t*>(InData);
uint64_t Value = *InBytes++ & uint8_t(0xff >> ByteCount);
switch (ByteCount - 1)
@@ -155,6 +152,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.
*
* @param InData A variable-length encoding of a signed integer.