Skip to content

Commit f054545

Browse files
committed
Simplify code: remove variables
1 parent 274d413 commit f054545

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

src/entropy/HuffmanDecoder.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ bool HuffmanDecoder::decodeChunk(byte block[], uint count)
228228
// State variables for each of the four parallel streams
229229
uint64 state0 = 0, state1 = 0, state2 = 0, state3 = 0; // bits read from bitstream
230230
uint8 bits0 = 0, bits1 = 0, bits2 = 0, bits3 = 0; // number of available bits in state
231-
uint8 bs0, bs1, bs2, bs3, shift;
232231

233-
#define READ_STATE(shift, state, idx, bits, bs) \
234-
shift = (56 - bits) & -8; \
235-
bs = bits + shift - DECODING_BATCH_SIZE; \
236-
state = (state << shift) | (uint64(BigEndian::readLong64(&_buffer[idx])) >> 1 >> (63 - shift)); /* handle shift = 0 */ \
237-
idx += (shift >> 3);
232+
#define READ_STATE(shift, state, idx, bits) do {\
233+
const uint8 shift = (56 - bits) & -8; \
234+
bits += shift - DECODING_BATCH_SIZE; \
235+
state = (state << shift) | (uint64(BigEndian::readLong64(&_buffer[idx])) >> 1 >> (63 - shift)); /* handle shift = 0 */ \
236+
idx += (shift >> 3); \
237+
} while (0);
238238

239239
const int szFrag = count / 4;
240240
byte* block0 = &block[0 * szFrag];
@@ -245,33 +245,33 @@ bool HuffmanDecoder::decodeChunk(byte block[], uint count)
245245

246246
while (n < szFrag - 4) {
247247
// Fill 64 bits of state from the bitstream for each stream
248-
READ_STATE(shift, state0, idx0, bits0, bs0);
249-
READ_STATE(shift, state1, idx1, bits1, bs1);
250-
READ_STATE(shift, state2, idx2, bits2, bs2);
251-
READ_STATE(shift, state3, idx3, bits3, bs3);
248+
READ_STATE(shift, state0, idx0, bits0);
249+
READ_STATE(shift, state1, idx1, bits1);
250+
READ_STATE(shift, state2, idx2, bits2);
251+
READ_STATE(shift, state3, idx3, bits3);
252252

253253
// Decompress 4 symbols per stream
254-
const uint16 val00 = _table[(state0 >> bs0) & TABLE_MASK]; bs0 -= uint8(val00);
255-
const uint16 val10 = _table[(state1 >> bs1) & TABLE_MASK]; bs1 -= uint8(val10);
256-
const uint16 val20 = _table[(state2 >> bs2) & TABLE_MASK]; bs2 -= uint8(val20);
257-
const uint16 val30 = _table[(state3 >> bs3) & TABLE_MASK]; bs3 -= uint8(val30);
258-
const uint16 val01 = _table[(state0 >> bs0) & TABLE_MASK]; bs0 -= uint8(val01);
259-
const uint16 val11 = _table[(state1 >> bs1) & TABLE_MASK]; bs1 -= uint8(val11);
260-
const uint16 val21 = _table[(state2 >> bs2) & TABLE_MASK]; bs2 -= uint8(val21);
261-
const uint16 val31 = _table[(state3 >> bs3) & TABLE_MASK]; bs3 -= uint8(val31);
262-
const uint16 val02 = _table[(state0 >> bs0) & TABLE_MASK]; bs0 -= uint8(val02);
263-
const uint16 val12 = _table[(state1 >> bs1) & TABLE_MASK]; bs1 -= uint8(val12);
264-
const uint16 val22 = _table[(state2 >> bs2) & TABLE_MASK]; bs2 -= uint8(val22);
265-
const uint16 val32 = _table[(state3 >> bs3) & TABLE_MASK]; bs3 -= uint8(val32);
266-
const uint16 val03 = _table[(state0 >> bs0) & TABLE_MASK]; bs0 -= uint8(val03);
267-
const uint16 val13 = _table[(state1 >> bs1) & TABLE_MASK]; bs1 -= uint8(val13);
268-
const uint16 val23 = _table[(state2 >> bs2) & TABLE_MASK]; bs2 -= uint8(val23);
269-
const uint16 val33 = _table[(state3 >> bs3) & TABLE_MASK]; bs3 -= uint8(val33);
270-
271-
bits0 = bs0 + DECODING_BATCH_SIZE;
272-
bits1 = bs1 + DECODING_BATCH_SIZE;
273-
bits2 = bs2 + DECODING_BATCH_SIZE;
274-
bits3 = bs3 + DECODING_BATCH_SIZE;
254+
const uint16 val00 = _table[(state0 >> bits0) & TABLE_MASK]; bits0 -= uint8(val00);
255+
const uint16 val10 = _table[(state1 >> bits1) & TABLE_MASK]; bits1 -= uint8(val10);
256+
const uint16 val20 = _table[(state2 >> bits2) & TABLE_MASK]; bits2 -= uint8(val20);
257+
const uint16 val30 = _table[(state3 >> bits3) & TABLE_MASK]; bits3 -= uint8(val30);
258+
const uint16 val01 = _table[(state0 >> bits0) & TABLE_MASK]; bits0 -= uint8(val01);
259+
const uint16 val11 = _table[(state1 >> bits1) & TABLE_MASK]; bits1 -= uint8(val11);
260+
const uint16 val21 = _table[(state2 >> bits2) & TABLE_MASK]; bits2 -= uint8(val21);
261+
const uint16 val31 = _table[(state3 >> bits3) & TABLE_MASK]; bits3 -= uint8(val31);
262+
const uint16 val02 = _table[(state0 >> bits0) & TABLE_MASK]; bits0 -= uint8(val02);
263+
const uint16 val12 = _table[(state1 >> bits1) & TABLE_MASK]; bits1 -= uint8(val12);
264+
const uint16 val22 = _table[(state2 >> bits2) & TABLE_MASK]; bits2 -= uint8(val22);
265+
const uint16 val32 = _table[(state3 >> bits3) & TABLE_MASK]; bits3 -= uint8(val32);
266+
const uint16 val03 = _table[(state0 >> bits0) & TABLE_MASK]; bits0 -= uint8(val03);
267+
const uint16 val13 = _table[(state1 >> bits1) & TABLE_MASK]; bits1 -= uint8(val13);
268+
const uint16 val23 = _table[(state2 >> bits2) & TABLE_MASK]; bits2 -= uint8(val23);
269+
const uint16 val33 = _table[(state3 >> bits3) & TABLE_MASK]; bits3 -= uint8(val33);
270+
271+
bits0 += DECODING_BATCH_SIZE;
272+
bits1 += DECODING_BATCH_SIZE;
273+
bits2 += DECODING_BATCH_SIZE;
274+
bits3 += DECODING_BATCH_SIZE;
275275

276276
block0[n + 0] = byte(val00 >> 8);
277277
block1[n + 0] = byte(val10 >> 8);
@@ -293,17 +293,17 @@ bool HuffmanDecoder::decodeChunk(byte block[], uint count)
293293
}
294294

295295
// Fill 64 bits of state from the bitstream for each stream
296-
READ_STATE(shift, state0, idx0, bits0, bs0);
297-
READ_STATE(shift, state1, idx1, bits1, bs1);
298-
READ_STATE(shift, state2, idx2, bits2, bs2);
299-
READ_STATE(shift, state3, idx3, bits3, bs3);
296+
READ_STATE(shift, state0, idx0, bits0);
297+
READ_STATE(shift, state1, idx1, bits1);
298+
READ_STATE(shift, state2, idx2, bits2);
299+
READ_STATE(shift, state3, idx3, bits3);
300300

301301
while (n < szFrag) {
302302
// Decompress 1 symbol per stream
303-
const uint16 val0 = _table[(state0 >> bs0) & TABLE_MASK]; bs0 -= uint8(val0);
304-
const uint16 val1 = _table[(state1 >> bs1) & TABLE_MASK]; bs1 -= uint8(val1);
305-
const uint16 val2 = _table[(state2 >> bs2) & TABLE_MASK]; bs2 -= uint8(val2);
306-
const uint16 val3 = _table[(state3 >> bs3) & TABLE_MASK]; bs3 -= uint8(val3);
303+
const uint16 val0 = _table[(state0 >> bits0) & TABLE_MASK]; bits0 -= uint8(val0);
304+
const uint16 val1 = _table[(state1 >> bits1) & TABLE_MASK]; bits1 -= uint8(val1);
305+
const uint16 val2 = _table[(state2 >> bits2) & TABLE_MASK]; bits2 -= uint8(val2);
306+
const uint16 val3 = _table[(state3 >> bits3) & TABLE_MASK]; bits3 -= uint8(val3);
307307

308308
block0[n] = byte(val0 >> 8);
309309
block1[n] = byte(val1 >> 8);

0 commit comments

Comments
 (0)