mirror of
https://github.com/google/brotli.git
synced 2024-12-28 02:31:05 +00:00
Fix -Wcast-align
warnings
This commit is contained in:
parent
74147a1a41
commit
b1db6f149a
30
dec/decode.c
30
dec/decode.c
@ -851,37 +851,38 @@ static BROTLI_INLINE BROTLI_BOOL SafeReadBlockLength(
|
||||
static BROTLI_NOINLINE void InverseMoveToFrontTransform(
|
||||
uint8_t* v, uint32_t v_len, BrotliDecoderState* state) {
|
||||
/* Reinitialize elements that could have been changed. */
|
||||
uint32_t i = 4;
|
||||
uint32_t i = 1;
|
||||
uint32_t upper_bound = state->mtf_upper_bound;
|
||||
uint8_t* mtf = &state->mtf[4]; /* Make mtf[-1] addressable. */
|
||||
uint32_t* mtf = &state->mtf[1]; /* Make mtf[-1] addressable. */
|
||||
uint8_t* mtf_u8 = (uint8_t*)mtf;
|
||||
/* Load endian-aware constant. */
|
||||
const uint8_t b0123[4] = {0, 1, 2, 3};
|
||||
uint32_t pattern;
|
||||
memcpy(&pattern, &b0123, 4);
|
||||
|
||||
/* Initialize list using 4 consequent values pattern. */
|
||||
*(uint32_t*)mtf = pattern;
|
||||
mtf[0] = pattern;
|
||||
do {
|
||||
pattern += 0x04040404; /* Advance all 4 values by 4. */
|
||||
*(uint32_t*)(mtf + i) = pattern;
|
||||
i += 4;
|
||||
mtf[i] = pattern;
|
||||
i++;
|
||||
} while (i <= upper_bound);
|
||||
|
||||
/* Transform the input. */
|
||||
upper_bound = 0;
|
||||
for (i = 0; i < v_len; ++i) {
|
||||
int index = v[i];
|
||||
uint8_t value = mtf[index];
|
||||
uint8_t value = mtf_u8[index];
|
||||
upper_bound |= v[i];
|
||||
v[i] = value;
|
||||
mtf[-1] = value;
|
||||
mtf_u8[-1] = value;
|
||||
do {
|
||||
index--;
|
||||
mtf[index + 1] = mtf[index];
|
||||
mtf_u8[index + 1] = mtf_u8[index];
|
||||
} while (index >= 0);
|
||||
}
|
||||
/* Remember amount of elements to be reinitialized. */
|
||||
state->mtf_upper_bound = upper_bound;
|
||||
state->mtf_upper_bound = upper_bound >> 2;
|
||||
}
|
||||
|
||||
/* Decodes a series of Huffman table using ReadHuffmanCode function. */
|
||||
@ -2142,24 +2143,23 @@ BrotliDecoderResult BrotliDecoderDecompressStream(
|
||||
{
|
||||
uint32_t num_distance_codes = s->num_direct_distance_codes +
|
||||
((2 * BROTLI_MAX_DISTANCE_BITS) << s->distance_postfix_bits);
|
||||
BROTLI_BOOL allocation_success = BROTLI_TRUE;
|
||||
result = DecodeContextMap(
|
||||
s->num_block_types[2] << BROTLI_DISTANCE_CONTEXT_BITS,
|
||||
&s->num_dist_htrees, &s->dist_context_map, s);
|
||||
if (result != BROTLI_DECODER_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
BrotliDecoderHuffmanTreeGroupInit(
|
||||
allocation_success &= BrotliDecoderHuffmanTreeGroupInit(
|
||||
s, &s->literal_hgroup, BROTLI_NUM_LITERAL_SYMBOLS,
|
||||
s->num_literal_htrees);
|
||||
BrotliDecoderHuffmanTreeGroupInit(
|
||||
allocation_success &= BrotliDecoderHuffmanTreeGroupInit(
|
||||
s, &s->insert_copy_hgroup, BROTLI_NUM_COMMAND_SYMBOLS,
|
||||
s->num_block_types[1]);
|
||||
BrotliDecoderHuffmanTreeGroupInit(
|
||||
allocation_success &= BrotliDecoderHuffmanTreeGroupInit(
|
||||
s, &s->distance_hgroup, num_distance_codes,
|
||||
s->num_dist_htrees);
|
||||
if (s->literal_hgroup.codes == 0 ||
|
||||
s->insert_copy_hgroup.codes == 0 ||
|
||||
s->distance_hgroup.codes == 0) {
|
||||
if (!allocation_success) {
|
||||
return SaveErrorCode(s,
|
||||
BROTLI_FAILURE(BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS));
|
||||
}
|
||||
|
14
dec/state.c
14
dec/state.c
@ -97,7 +97,7 @@ void BrotliDecoderStateInitWithCustomAllocators(BrotliDecoderState* s,
|
||||
/* Make small negative indexes addressable. */
|
||||
s->symbol_lists = &s->symbols_lists_array[BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1];
|
||||
|
||||
s->mtf_upper_bound = 255;
|
||||
s->mtf_upper_bound = 63;
|
||||
}
|
||||
|
||||
void BrotliDecoderStateMetablockBegin(BrotliDecoderState* s) {
|
||||
@ -148,22 +148,24 @@ void BrotliDecoderStateCleanup(BrotliDecoderState* s) {
|
||||
BROTLI_FREE(s, s->block_type_trees);
|
||||
}
|
||||
|
||||
void BrotliDecoderHuffmanTreeGroupInit(BrotliDecoderState* s,
|
||||
BROTLI_BOOL BrotliDecoderHuffmanTreeGroupInit(BrotliDecoderState* s,
|
||||
HuffmanTreeGroup* group, uint32_t alphabet_size, uint32_t ntrees) {
|
||||
/* Pack two allocations into one */
|
||||
const size_t max_table_size = kMaxHuffmanTableSize[(alphabet_size + 31) >> 5];
|
||||
const size_t code_size = sizeof(HuffmanCode) * ntrees * max_table_size;
|
||||
const size_t htree_size = sizeof(HuffmanCode*) * ntrees;
|
||||
char* p = (char*)BROTLI_ALLOC(s, code_size + htree_size);
|
||||
/* Pointer alignment is, hopefully, wider than sizeof(HuffmanCode). */
|
||||
HuffmanCode** p = (HuffmanCode**)BROTLI_ALLOC(s, code_size + htree_size);
|
||||
group->alphabet_size = (uint16_t)alphabet_size;
|
||||
group->num_htrees = (uint16_t)ntrees;
|
||||
group->codes = (HuffmanCode*)p;
|
||||
group->htrees = (HuffmanCode**)(p + code_size);
|
||||
group->htrees = (HuffmanCode**)p;
|
||||
group->codes = (HuffmanCode*)(&p[ntrees]);
|
||||
return !!p;
|
||||
}
|
||||
|
||||
void BrotliDecoderHuffmanTreeGroupRelease(
|
||||
BrotliDecoderState* s, HuffmanTreeGroup* group) {
|
||||
BROTLI_FREE(s, group->codes);
|
||||
BROTLI_FREE(s, group->htrees);
|
||||
group->htrees = NULL;
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ struct BrotliDecoderStateStruct {
|
||||
|
||||
/* For InverseMoveToFrontTransform */
|
||||
uint32_t mtf_upper_bound;
|
||||
uint8_t mtf[256 + 4];
|
||||
uint32_t mtf[64 + 1];
|
||||
|
||||
/* For custom dictionaries */
|
||||
const uint8_t* custom_dict;
|
||||
@ -235,7 +235,7 @@ BROTLI_INTERNAL void BrotliDecoderStateCleanup(BrotliDecoderState* s);
|
||||
BROTLI_INTERNAL void BrotliDecoderStateMetablockBegin(BrotliDecoderState* s);
|
||||
BROTLI_INTERNAL void BrotliDecoderStateCleanupAfterMetablock(
|
||||
BrotliDecoderState* s);
|
||||
BROTLI_INTERNAL void BrotliDecoderHuffmanTreeGroupInit(
|
||||
BROTLI_INTERNAL BROTLI_BOOL BrotliDecoderHuffmanTreeGroupInit(
|
||||
BrotliDecoderState* s, HuffmanTreeGroup* group, uint32_t alphabet_size,
|
||||
uint32_t ntrees);
|
||||
BROTLI_INTERNAL void BrotliDecoderHuffmanTreeGroupRelease(
|
||||
|
Loading…
Reference in New Issue
Block a user