1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 08:43:09 +00:00

Small tweak to decode loop

This commit is contained in:
Marco Costalba 2016-05-14 14:43:15 +02:00
parent 7dd8fd77b2
commit 57c229a7a2

View file

@ -551,18 +551,18 @@ int decompress_pairs(PairsData* d, uint64_t idx)
int buf64Size = 64; int buf64Size = 64;
Sym sym; Sym sym;
for (;;) { while (true) {
int len = d->min_sym_len; int len = 0; // This is the symbol length - d->min_sym_len
// Now get the symbol length. For any symbol s64 of length l right-padded // Now get the symbol length. For any symbol s64 of length l right-padded
// to 64 bits holds d->base64[l-1] >= s64 >= d->base64[l] so we can find // to 64 bits holds d->base64[l-1] >= s64 >= d->base64[l] so we can find
// the symbol length iterating through base64[]. // the symbol length iterating through base64[].
while (buf64 < d->base64[len - d->min_sym_len]) while (buf64 < d->base64[len])
++len; ++len;
// Symbols of same length are mapped to consecutive numbers, so we can compute // Symbols of same length are mapped to consecutive numbers, so we can compute
// the offset of our symbol of length len, stored at the beginning of buf64. // the offset of our symbol of length len, stored at the beginning of buf64.
sym = (buf64 - d->base64[len - d->min_sym_len]) >> (64 - len); sym = (buf64 - d->base64[len]) >> (64 - len - d->min_sym_len);
// Now add the value of the lowest symbol of length len to get our symbol // Now add the value of the lowest symbol of length len to get our symbol
sym += number<Sym, LittleEndian>(&d->lowestSym[len]); sym += number<Sym, LittleEndian>(&d->lowestSym[len]);
@ -574,6 +574,7 @@ int decompress_pairs(PairsData* d, uint64_t idx)
// ...otherwise update the offset and continue to iterate // ...otherwise update the offset and continue to iterate
idxOffset -= d->symlen[sym] + 1; idxOffset -= d->symlen[sym] + 1;
len += d->min_sym_len; // Get the real length
buf64 <<= len; // Consume the just processed symbol buf64 <<= len; // Consume the just processed symbol
buf64Size -= len; buf64Size -= len;
@ -989,8 +990,6 @@ uint8_t* set_sizes(PairsData* d, uint8_t* data, uint64_t tb_size)
for (size_t i = 0; i < d->base64.size(); ++i) for (size_t i = 0; i < d->base64.size(); ++i)
d->base64[i] <<= 64 - i - d->min_sym_len; // Right-padding to 64 bits d->base64[i] <<= 64 - i - d->min_sym_len; // Right-padding to 64 bits
d->lowestSym -= d->min_sym_len;
data += d->base64.size() * sizeof(Sym); data += d->base64.size() * sizeof(Sym);
d->symlen.resize(number<uint16_t, LittleEndian>(data)); data += sizeof(uint16_t); d->symlen.resize(number<uint16_t, LittleEndian>(data)); data += sizeof(uint16_t);
d->btree = (LR*)data; d->btree = (LR*)data;