Z_INTERNAL block_state deflate_slow (deflate_state *s, int flush);
Z_INTERNAL block_state deflate_rle (deflate_state *s, int flush);
Z_INTERNAL block_state deflate_huff (deflate_state *s, int flush);
+static void lm_set_level (deflate_state *s, int level);
static void lm_init (deflate_state *s);
Z_INTERNAL unsigned read_buf (PREFIX3(stream) *strm, unsigned char *buf, unsigned size);
}
s->matches = 0;
}
- s->level = level;
- s->max_lazy_match = configuration_table[level].max_lazy;
- s->good_match = configuration_table[level].good_length;
- s->nice_match = configuration_table[level].nice_length;
- s->max_chain_length = configuration_table[level].max_chain;
+
+ lm_set_level(s, level);
}
s->strategy = strategy;
return Z_OK;
return len;
}
+/* ===========================================================================
+ * Set longest match variables based on level configuration
+ */
+static void lm_set_level(deflate_state *s, int level) {
+ s->max_lazy_match = configuration_table[level].max_lazy;
+ s->good_match = configuration_table[level].good_length;
+ s->nice_match = configuration_table[level].nice_length;
+ s->max_chain_length = configuration_table[level].max_chain;
+
+ s->update_hash = functable.update_hash;
+ s->insert_string = functable.insert_string;
+ s->quick_insert_string = functable.quick_insert_string;
+
+ s->level = level;
+}
+
/* ===========================================================================
* Initialize the "longest match" routines for a new zlib stream
*/
/* Set the default configuration parameters:
*/
- s->max_lazy_match = configuration_table[s->level].max_lazy;
- s->good_match = configuration_table[s->level].good_length;
- s->nice_match = configuration_table[s->level].nice_length;
- s->max_chain_length = configuration_table[s->level].max_chain;
+ lm_set_level(s, s->level);
s->strstart = 0;
s->block_start = 0;
if (s->lookahead + s->insert >= STD_MIN_MATCH) {
unsigned int str = s->strstart - s->insert;
if (str >= 1)
- functable.quick_insert_string(s, str + 2 - STD_MIN_MATCH);
+ s->quick_insert_string(s, str + 2 - STD_MIN_MATCH);
unsigned int count;
if (UNLIKELY(s->lookahead == 1)) {
count = s->insert - 1;
count = s->insert;
}
if (count > 0) {
- functable.insert_string(s, str, count);
+ s->insert_string(s, str, count);
s->insert -= count;
}
}
/* A Pos is an index in the character window. We use short instead of int to
* save space in the various tables.
*/
+/* Type definitions for hash callbacks */
+typedef struct internal_state deflate_state;
-typedef struct internal_state {
+typedef uint32_t (* update_hash_cb) (deflate_state *const s, uint32_t h, uint32_t val);
+typedef void (* insert_string_cb) (deflate_state *const s, uint32_t str, uint32_t count);
+typedef Pos (* quick_insert_string_cb)(deflate_state *const s, uint32_t str);
+
+struct internal_state {
PREFIX3(stream) *strm; /* pointer back to this zlib stream */
unsigned char *pending_buf; /* output still pending */
unsigned char *pending_out; /* next pending byte to output to the stream */
* max_insert_length is used only for compression levels <= 3.
*/
+ update_hash_cb update_hash;
+ insert_string_cb insert_string;
+ quick_insert_string_cb quick_insert_string;
+ /* Hash function callbacks that can be configured depending on the deflate
+ * algorithm being used */
+
int level; /* compression level (1..9) */
int strategy; /* favor or force Huffman coding*/
/* Reserved for future use and alignment purposes */
int32_t reserved[11];
-} ALIGNED_(8) deflate_state;
+} ALIGNED_(8);
typedef enum {
need_more, /* block not completed, need more input or more output */
*/
hash_head = 0;
if (LIKELY(s->lookahead >= WANT_MIN_MATCH)) {
- hash_head = functable.quick_insert_string(s, s->strstart);
+ hash_head = s->quick_insert_string(s, s->strstart);
}
/* Find the longest match, discarding those <= prev_length.
unsigned int insert_cnt = mov_fwd;
if (UNLIKELY(insert_cnt > max_insert - s->strstart))
insert_cnt = max_insert - s->strstart;
-
- functable.insert_string(s, s->strstart + 1, insert_cnt);
+ s->insert_string(s, s->strstart + 1, insert_cnt);
}
s->prev_length = 0;
s->match_available = 0;