Skip to content

Commit 0fe6457

Browse files
authored
perf: Reduce huffman decode table size (#871)
1 parent e793b24 commit 0fe6457

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/hpack/huffman/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use bytes::{BufMut, BytesMut};
77

88
// Constructed in the generated `table.rs` file
99
struct Decoder {
10-
state: usize,
10+
state: u8,
1111
maybe_eos: bool,
1212
}
1313

@@ -76,7 +76,7 @@ impl Decoder {
7676
// Decodes 4 bits
7777
fn decode4(&mut self, input: u8) -> Result<Option<u8>, DecoderError> {
7878
// (next-state, byte, flags)
79-
let (next, byte, flags) = DECODE_TABLE[self.state][input as usize];
79+
let (next, byte, flags) = DECODE_TABLE[self.state as usize][input as usize];
8080

8181
if flags & ERROR == ERROR {
8282
// Data followed the EOS marker

src/hpack/huffman/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ pub const ENCODE_TABLE: [(usize, u64); 257] = [
262262
];
263263

264264
// (next-state, byte, flags)
265-
pub const DECODE_TABLE: [[(usize, u8, u8); 16]; 256] = [
265+
pub const DECODE_TABLE: [[(u8, u8, u8); 16]; 256] = [
266266
// 0
267267
[
268268
(4, 0, 0x00),

util/genhuff/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ pub fn main() {
249249

250250
println!();
251251
println!("// (next-state, byte, flags)");
252-
println!("pub const DECODE_TABLE: [[(usize, u8, u8); 16]; 256] = [");
252+
println!("pub const DECODE_TABLE: [[(u8, u8, u8); 16]; 256] = [");
253253

254254
decode.print();
255255

0 commit comments

Comments
 (0)