Skip to content

Commit bb2c510

Browse files
committed
Move part of fill_window out of the inlined path
1 parent d1e4c26 commit bb2c510

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

zlib-rs/src/deflate.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,27 +1782,8 @@ pub(crate) fn fill_window(stream: &mut DeflateStream) {
17821782
let n = read_buf_window(stream, stream.state.strstart + stream.state.lookahead, more);
17831783

17841784
let state = &mut stream.state;
1785-
state.lookahead += n;
1786-
1787-
// Initialize the hash value now that we have some input:
1788-
if state.lookahead + state.insert >= STD_MIN_MATCH {
1789-
let string = state.strstart - state.insert;
1790-
if state.max_chain_length > 1024 {
1791-
let v0 = state.window.filled()[string] as u32;
1792-
let v1 = state.window.filled()[string + 1] as u32;
1793-
state.ins_h = state.update_hash(v0, v1) as usize;
1794-
} else if string >= 1 {
1795-
state.quick_insert_string(string + 2 - STD_MIN_MATCH);
1796-
}
1797-
let mut count = state.insert;
1798-
if state.lookahead == 1 {
1799-
count -= 1;
1800-
}
1801-
if count > 0 {
1802-
state.insert_string(string, count);
1803-
state.insert -= count;
1804-
}
1805-
}
1785+
1786+
fill_window_help(n, state);
18061787

18071788
// If the whole input has less than STD_MIN_MATCH bytes, ins_h is garbage,
18081789
// but this is not important since only literal bytes will be emitted.
@@ -1823,6 +1804,30 @@ pub(crate) fn fill_window(stream: &mut DeflateStream) {
18231804
);
18241805
}
18251806

1807+
fn fill_window_help(n: usize, state: &mut &mut State) {
1808+
state.lookahead += n;
1809+
1810+
// Initialize the hash value now that we have some input:
1811+
if state.lookahead + state.insert >= STD_MIN_MATCH {
1812+
let string = state.strstart - state.insert;
1813+
if state.max_chain_length > 1024 {
1814+
let v0 = state.window.filled()[string] as u32;
1815+
let v1 = state.window.filled()[string + 1] as u32;
1816+
state.ins_h = state.update_hash(v0, v1) as usize;
1817+
} else if string >= 1 {
1818+
state.quick_insert_string(string + 2 - STD_MIN_MATCH);
1819+
}
1820+
let mut count = state.insert;
1821+
if state.lookahead == 1 {
1822+
count -= 1;
1823+
}
1824+
if count > 0 {
1825+
state.insert_string(string, count);
1826+
state.insert -= count;
1827+
}
1828+
}
1829+
}
1830+
18261831
pub(crate) struct StaticTreeDesc {
18271832
/// static tree or NULL
18281833
pub(crate) static_tree: &'static [Value],

0 commit comments

Comments
 (0)