diff --git a/base/stl_add.hpp b/base/stl_add.hpp index 9f9d5437b9..e252a8b53e 100644 --- a/base/stl_add.hpp +++ b/base/stl_add.hpp @@ -88,9 +88,16 @@ struct DeleteFunctor struct NoopFunctor { - template void operator () (T const & value) const + template inline void operator () (T const &) const { - UNUSED_VALUE(value); + } +}; + +struct IdFunctor +{ + template inline T operator () (T const & x) const + { + return x; } }; diff --git a/coding/varint.hpp b/coding/varint.hpp index afe0c5e28e..64b2191290 100644 --- a/coding/varint.hpp +++ b/coding/varint.hpp @@ -4,6 +4,7 @@ #include "../base/assert.hpp" #include "../base/base.hpp" #include "../base/exception.hpp" +#include "../base/stl_add.hpp" #include "../std/type_traits.hpp" @@ -215,8 +216,9 @@ private: size_t m_Remaining; }; -template -void const * ReadVarInt64Array(void const * pBeg, WhileConditionT whileCondition, F f) +template +inline void const * ReadVarInt64Array(void const * pBeg, WhileConditionT whileCondition, + F f, ConverterT converter) { uint8_t const * const pBegChar = static_cast(pBeg); uint64_t res64 = 0; @@ -231,7 +233,7 @@ void const * ReadVarInt64Array(void const * pBeg, WhileConditionT whileCondition count32 += 7; if (!(t & 128)) { - f(ZigZagDecode((static_cast(res32) << count64) + res64)); + f(converter((static_cast(res32) << count64) + res64)); whileCondition.NextVarInt(); res64 = 0; res32 = 0; @@ -257,12 +259,26 @@ void const * ReadVarInt64Array(void const * pBeg, WhileConditionT whileCondition template inline void const * ReadVarInt64Array(void const * pBeg, void const * pEnd, F f) { - return impl::ReadVarInt64Array(pBeg, impl::ReadVarInt64ArrayUntilBufferEnd(pEnd), f); + return impl::ReadVarInt64Array( + pBeg, impl::ReadVarInt64ArrayUntilBufferEnd(pEnd), f, &ZigZagDecode); +} + +template inline +void const * ReadVarUint64Array(void const * pBeg, void const * pEnd, F f) +{ + return impl::ReadVarInt64Array(pBeg, impl::ReadVarInt64ArrayUntilBufferEnd(pEnd), f, IdFunctor()); } template inline void const * ReadVarInt64Array(void const * pBeg, size_t count, F f) { - return impl::ReadVarInt64Array(pBeg, impl::ReadVarInt64ArrayGivenSize(count), f); + return impl::ReadVarInt64Array( + pBeg, impl::ReadVarInt64ArrayGivenSize(count), f, &ZigZagDecode); +} + +template inline +void const * ReadVarUint64Array(void const * pBeg, size_t count, F f) +{ + return impl::ReadVarInt64Array(pBeg, impl::ReadVarInt64ArrayGivenSize(count), f, IdFunctor()); }