Revert "Refactor lpDecodeBacklen for loop-based decoding, improving readability and branch efficiency."

This reverts commit af52aacff8.
This commit is contained in:
fcostaoliveira 2024-11-13 17:32:32 +00:00
parent af52aacff8
commit 09f6680ba0
1 changed files with 9 additions and 8 deletions

View File

@ -373,14 +373,15 @@ static inline unsigned long lpEncodeBacklen(unsigned char *buf, uint64_t l) {
* 5 bytes are used), UINT64_MAX is returned to report the problem. */
static inline uint64_t lpDecodeBacklen(unsigned char *p) {
uint64_t val = 0;
for (uint64_t shift = 0; shift <= 28; shift += 7) {
val |= (uint64_t)(*p & 127) << shift;
if (!(*p & 128)) {
return val;
}
p--; // Move to the previous byte
}
return UINT64_MAX; // Invalid encoding if we exceed 5 bytes
uint64_t shift = 0;
do {
val |= (uint64_t)(p[0] & 127) << shift;
if (!(p[0] & 128)) break;
shift += 7;
p--;
if (shift > 28) return UINT64_MAX;
} while(1);
return val;
}
/* Encode the string element pointed by 's' of size 'len' in the target