mirror of
https://github.com/cuberite/libdeflate.git
synced 2025-09-11 13:32:14 -04:00
deflate_compress: refactor writing literals into separate function
Avoid too many levels of indentation.
This commit is contained in:
parent
f6e7593cfc
commit
08692b8696
@ -1592,23 +1592,12 @@ deflate_write_huffman_header(struct libdeflate_compressor *c,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static forceinline void
|
||||||
deflate_write_sequences(struct deflate_output_bitstream * restrict os,
|
deflate_write_literal_run(struct deflate_output_bitstream *os,
|
||||||
const struct deflate_codes * restrict codes,
|
const u8 *in_next, u32 litrunlen,
|
||||||
const struct deflate_sequence sequences[restrict],
|
const struct deflate_codes *codes)
|
||||||
const u8 * restrict in_next)
|
|
||||||
{
|
{
|
||||||
const struct deflate_sequence *seq = sequences;
|
#if 1
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
u32 litrunlen = seq->litrunlen_and_length & 0x7FFFFF;
|
|
||||||
unsigned length = seq->litrunlen_and_length >> 23;
|
|
||||||
unsigned length_slot;
|
|
||||||
unsigned litlen_symbol;
|
|
||||||
unsigned offset_symbol;
|
|
||||||
|
|
||||||
if (litrunlen) {
|
|
||||||
#if 1
|
|
||||||
while (litrunlen >= 4) {
|
while (litrunlen >= 4) {
|
||||||
unsigned lit0 = in_next[0];
|
unsigned lit0 = in_next[0];
|
||||||
unsigned lit1 = in_next[1];
|
unsigned lit1 = in_next[1];
|
||||||
@ -1649,7 +1638,8 @@ deflate_write_sequences(struct deflate_output_bitstream * restrict os,
|
|||||||
deflate_flush_bits(os);
|
deflate_flush_bits(os);
|
||||||
in_next++;
|
in_next++;
|
||||||
if (litrunlen-- != 0) {
|
if (litrunlen-- != 0) {
|
||||||
deflate_add_bits(os, codes->codewords.litlen[*in_next],
|
deflate_add_bits(os,
|
||||||
|
codes->codewords.litlen[*in_next],
|
||||||
codes->lens.litlen[*in_next]);
|
codes->lens.litlen[*in_next]);
|
||||||
if (!CAN_BUFFER(3 * MAX_LITLEN_CODEWORD_LEN))
|
if (!CAN_BUFFER(3 * MAX_LITLEN_CODEWORD_LEN))
|
||||||
deflate_flush_bits(os);
|
deflate_flush_bits(os);
|
||||||
@ -1659,14 +1649,36 @@ deflate_write_sequences(struct deflate_output_bitstream * restrict os,
|
|||||||
if (CAN_BUFFER(3 * MAX_LITLEN_CODEWORD_LEN))
|
if (CAN_BUFFER(3 * MAX_LITLEN_CODEWORD_LEN))
|
||||||
deflate_flush_bits(os);
|
deflate_flush_bits(os);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
do {
|
do {
|
||||||
unsigned lit = *in_next++;
|
unsigned lit = *in_next++;
|
||||||
|
|
||||||
deflate_add_bits(os, codes->codewords.litlen[lit],
|
deflate_add_bits(os, codes->codewords.litlen[lit],
|
||||||
codes->lens.litlen[lit]);
|
codes->lens.litlen[lit]);
|
||||||
deflate_flush_bits(os);
|
deflate_flush_bits(os);
|
||||||
} while (--litrunlen);
|
} while (--litrunlen);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
deflate_write_sequences(struct deflate_output_bitstream * restrict os,
|
||||||
|
const struct deflate_codes * restrict codes,
|
||||||
|
const struct deflate_sequence sequences[restrict],
|
||||||
|
const u8 * restrict in_next)
|
||||||
|
{
|
||||||
|
const struct deflate_sequence *seq = sequences;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
u32 litrunlen = seq->litrunlen_and_length & 0x7FFFFF;
|
||||||
|
unsigned length = seq->litrunlen_and_length >> 23;
|
||||||
|
unsigned length_slot;
|
||||||
|
unsigned litlen_symbol;
|
||||||
|
unsigned offset_symbol;
|
||||||
|
|
||||||
|
if (litrunlen) {
|
||||||
|
deflate_write_literal_run(os, in_next, litrunlen,
|
||||||
|
codes);
|
||||||
|
in_next += litrunlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user