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