From d92a161c46fcb46afd1ba9c5167043fce71c3ed7 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 5 Nov 2013 23:34:58 +0900 Subject: [PATCH] nghttp2_hd_huffman: Code cleanup --- lib/nghttp2_hd_huffman.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/nghttp2_hd_huffman.c b/lib/nghttp2_hd_huffman.c index a3891040..fd2a5d9e 100644 --- a/lib/nghttp2_hd_huffman.c +++ b/lib/nghttp2_hd_huffman.c @@ -100,20 +100,21 @@ static uint8_t huff_get_lsb_aligned(const nghttp2_huff_sym *sym, size_t codebitoff, size_t nbits) { - uint8_t a = sym->code[codebitoff/8]; + size_t codeidx = codebitoff / 8; + uint8_t a = sym->code[codeidx]; size_t localbitoff = codebitoff & 0x7; size_t bitleft = 8 - localbitoff; if(bitleft >= nbits) { return (a >> (bitleft - nbits)) & ((1 << nbits) - 1); } else { - uint8_t b = 0; + size_t right = nbits - bitleft; a &= ((1 << bitleft) - 1); - a <<= nbits - bitleft; - if((sym->nbits + 7) / 8 > codebitoff / 8 + 1) { - b = sym->code[codebitoff / 8 + 1] >> (8 - (nbits - bitleft)); + a <<= right; + if((sym->nbits + 7) / 8 > codeidx + 1) { + a |= sym->code[codeidx + 1] >> (8 - right); } - return a | b; + return a; } }