Index: c_src/KinoSearch/Util/MathUtils.h =================================================================== --- c_src/KinoSearch/Util/MathUtils.h (revision 4018) +++ c_src/KinoSearch/Util/MathUtils.h (working copy) @@ -113,19 +113,26 @@ *out_buf += sizeof(buf); } +/* Decode a compressed integer up to size of 'var', advancing 'source' */ +#define KINO_MATH_DECODE(var, source) \ + do { \ + var = (*source & 0x7f); \ + while (*source++ & 0x80) { \ + var = (*source & 0x7f) | (var << 7); \ + } \ + } while (0) + /** Read a compressed 32-bit integer from the buffer pointed to by the source * pointer. Advance the pointer, consuming the bytes occupied by the C32. */ static CHY_INLINE chy_u32_t kino_Math_decode_c32(char **source_ptr) { - chy_u32_t retval = 0; - chy_u8_t *ptr = (chy_u8_t*)*source_ptr; - do { - retval = (retval << 7) | (*ptr & 0x7f); - } while ((*ptr++ & 0x80) != 0); - *source_ptr = (char*)ptr; - return retval; + char *source = *source_ptr; + chy_u32_t decoded = (*source & 0x7f); + KINO_MATH_DECODE(decoded, source); + *source_ptr = source; + return decoded; } /** Read a compressed 64-bit integer from the buffer pointed to by the source @@ -134,13 +141,11 @@ static CHY_INLINE chy_u64_t kino_Math_decode_c64(char **source_ptr) { - chy_u64_t retval = 0; - chy_u8_t *ptr = (chy_u8_t*)*source_ptr; - do { - retval = (retval << 7) | (*ptr & 0x7f); - } while ((*ptr++ & 0x80) != 0); - *source_ptr = (char*)ptr; - return retval; + char *source = *source_ptr; + chy_u64_t decoded = (*source & 0x7f); + KINO_MATH_DECODE(decoded, source); + *source_ptr = source; + return decoded; } /* Advance a pointer past one encoded C32.