Merge pull request #2683 from nghttp2/optimize-hpack-huffman-decode-length-estimation

Optimize the decoded length estimation for Huffman encoded string
This commit is contained in:
Tatsuhiro Tsujikawa
2026-04-16 01:00:13 +09:00
committed by GitHub
2 changed files with 14 additions and 4 deletions

View File

@@ -2059,8 +2059,9 @@ nghttp2_ssize nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater,
inflater->state = NGHTTP2_HD_STATE_NEWNAME_READ_NAMEHUFF;
rv =
nghttp2_rcbuf_new(&inflater->namercbuf, inflater->left * 2 + 1, mem);
rv = nghttp2_rcbuf_new(
&inflater->namercbuf,
nghttp2_huff_estimate_decode_length(inflater->left) + 1, mem);
} else {
inflater->state = NGHTTP2_HD_STATE_NEWNAME_READ_NAME;
rv = nghttp2_rcbuf_new(&inflater->namercbuf, inflater->left + 1, mem);
@@ -2144,8 +2145,9 @@ nghttp2_ssize nghttp2_hd_inflate_hd_nv(nghttp2_hd_inflater *inflater,
inflater->state = NGHTTP2_HD_STATE_READ_VALUEHUFF;
rv =
nghttp2_rcbuf_new(&inflater->valuercbuf, inflater->left * 2 + 1, mem);
rv = nghttp2_rcbuf_new(
&inflater->valuercbuf,
nghttp2_huff_estimate_decode_length(inflater->left) + 1, mem);
} else {
inflater->state = NGHTTP2_HD_STATE_READ_VALUE;

View File

@@ -71,4 +71,12 @@ typedef struct {
extern const nghttp2_huff_sym huff_sym_table[];
extern const nghttp2_huff_decode huff_decode_table[][16];
/*
* nghttp2_huff_estimate_decode_length returns the estimated decoded
* length of the huffman encoded string of length |len|.
*/
static inline size_t nghttp2_huff_estimate_decode_length(size_t len) {
return len * 8 / 5;
}
#endif /* !defined(NGHTTP2_HD_HUFFMAN_H) */