@@ -56,13 +56,6 @@ static size_t uzlib_lz77_search_max_match(struct uzlib_lz77_state *state, const
56
56
57
57
// Compress the given chunk of data.
58
58
void uzlib_lz77_compress (struct uzlib_lz77_state * state , const uint8_t * src , unsigned len ) {
59
- bool use_src_as_history = false;
60
- if (state -> hist_buf == NULL ) {
61
- use_src_as_history = true;
62
- state -> hist_buf = (uint8_t * )src ;
63
- state -> hist_len = 0 ;
64
- }
65
-
66
59
const uint8_t * top = src + len ;
67
60
while (src < top ) {
68
61
// Look for a match in the history window.
@@ -77,31 +70,16 @@ void uzlib_lz77_compress(struct uzlib_lz77_state *state, const uint8_t *src, uns
77
70
zlib_match (& state -> outbuf , match_offset , match_len );
78
71
}
79
72
80
- // Advance the history window.
81
- if (use_src_as_history ) {
82
- // Use src as the history, so advance it.
83
- state -> hist_len += match_len ;
84
- if (state -> hist_len > state -> hist_max ) {
85
- state -> hist_buf += state -> hist_len - state -> hist_max ;
86
- state -> hist_len = state -> hist_max ;
87
- }
88
- src += match_len ;
89
- } else {
90
- // Push the bytes into the history buffer.
91
- size_t mask = state -> hist_max - 1 ;
92
- while (match_len -- ) {
93
- uint8_t b = * src ++ ;
94
- state -> hist_buf [(state -> hist_start + state -> hist_len ) & mask ] = b ;
95
- if (state -> hist_len == state -> hist_max ) {
96
- state -> hist_start = (state -> hist_start + 1 ) & mask ;
97
- } else {
98
- ++ state -> hist_len ;
99
- }
73
+ // Push the bytes into the history buffer.
74
+ size_t mask = state -> hist_max - 1 ;
75
+ while (match_len -- ) {
76
+ uint8_t b = * src ++ ;
77
+ state -> hist_buf [(state -> hist_start + state -> hist_len ) & mask ] = b ;
78
+ if (state -> hist_len == state -> hist_max ) {
79
+ state -> hist_start = (state -> hist_start + 1 ) & mask ;
80
+ } else {
81
+ ++ state -> hist_len ;
100
82
}
101
83
}
102
84
}
103
-
104
- if (use_src_as_history ) {
105
- state -> hist_buf = NULL ;
106
- }
107
85
}
0 commit comments