mirror of
https://github.com/nghttp2/nghttp2.git
synced 2026-06-21 18:49:19 +08:00
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:
@@ -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;
|
||||
|
||||
|
||||
@@ -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) */
|
||||
|
||||
Reference in New Issue
Block a user