Differences From Artifact [c0d670c09d]:
- File src/huffman_tree.h — part of check-in [0509d7a844] at 2019-01-03 19:13:03 on branch trunk — Update copyright (user: js, size: 1365) [annotate] [blame] [check-ins using]
To Artifact [f55f1d77c2]:
- File
src/huffman_tree.h
— part of check-in
[6a0bf8be32]
at
2019-03-20 21:04:36
on branch trunk
— Force inline tryReadBits and of_huffman_tree_walk
This gives a significant performance improvement, cutting decompression
time almost in half. (user: js, size: 1760) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | */ #include <stdbool.h> #include <stdint.h> #import "macros.h" OF_ASSUME_NONNULL_BEGIN struct of_huffman_tree { struct of_huffman_tree *_Nullable leaves[2]; uint16_t value; }; #ifdef __cplusplus extern "C" { #endif extern struct of_huffman_tree *_Nonnull of_huffman_tree_construct( uint8_t lengths[_Nonnull], uint16_t count); extern struct of_huffman_tree *_Nonnull of_huffman_tree_construct_single( uint16_t value); | > > > > > > > > > > > > > > > > > > > > > > > > > > < < < | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | */ #include <stdbool.h> #include <stdint.h> #import "macros.h" #import "OFInvalidFormatException.h" OF_ASSUME_NONNULL_BEGIN struct of_huffman_tree { struct of_huffman_tree *_Nullable leaves[2]; uint16_t value; }; static OF_INLINE bool of_huffman_tree_walk(id _Nullable stream, bool (*bitReader)(id _Nullable, uint16_t *_Nonnull, uint8_t), struct of_huffman_tree *_Nonnull *_Nonnull tree, uint16_t *_Nonnull value) { struct of_huffman_tree *iter = *tree; uint16_t bits; while (iter->value == 0xFFFF) { if OF_UNLIKELY (!bitReader(stream, &bits, 1)) { *tree = iter; return false; } if OF_UNLIKELY (iter->leaves[bits] == NULL) @throw [OFInvalidFormatException exception]; iter = iter->leaves[bits]; } *value = iter->value; return true; } #ifdef __cplusplus extern "C" { #endif extern struct of_huffman_tree *_Nonnull of_huffman_tree_construct( uint8_t lengths[_Nonnull], uint16_t count); extern struct of_huffman_tree *_Nonnull of_huffman_tree_construct_single( uint16_t value); extern void of_huffman_tree_release(struct of_huffman_tree *_Nonnull tree); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |