Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: net/spdy/core/hpack/hpack_huffman_decoder.cc

Issue 2908763002: Change HpackHuffmanDecoder::CanonicalToSource() return type. (Closed)
Patch Set: Re: #15. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Decoder for strings encoded using the HPACK Huffman Code (see 5 // Decoder for strings encoded using the HPACK Huffman Code (see
6 // https://httpwg.github.io/specs/rfc7541.html#huffman.code). 6 // https://httpwg.github.io/specs/rfc7541.html#huffman.code).
7 // 7 //
8 // This implementation is inspired by the One-Shift algorithm described in 8 // This implementation is inspired by the One-Shift algorithm described in
9 // "On the Implementation of Minimum Redundancy Prefix Codes", by Alistair 9 // "On the Implementation of Minimum Redundancy Prefix Codes", by Alistair
10 // Moffat and Andrew Turpin, 1997. 10 // Moffat and Andrew Turpin, 1997.
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // What is the position of the canonical symbol being decoded within 285 // What is the position of the canonical symbol being decoded within
286 // the canonical symbols of length |code_length|? 286 // the canonical symbols of length |code_length|?
287 HuffmanWord ordinal_in_length = 287 HuffmanWord ordinal_in_length =
288 ((bits - first_lj_code) >> (kHuffmanWordLength - code_length)); 288 ((bits - first_lj_code) >> (kHuffmanWordLength - code_length));
289 289
290 // Combined these two to produce the position of the canonical symbol 290 // Combined these two to produce the position of the canonical symbol
291 // being decoded within all of the canonical symbols. 291 // being decoded within all of the canonical symbols.
292 return first_canonical + ordinal_in_length; 292 return first_canonical + ordinal_in_length;
293 } 293 }
294 294
295 char HpackHuffmanDecoder::CanonicalToSource(HuffmanWord canonical) { 295 uint8_t HpackHuffmanDecoder::CanonicalToSource(HuffmanWord canonical) {
296 DCHECK_LT(canonical, 256u); 296 DCHECK_LT(canonical, 256u);
297 return static_cast<char>(kCanonicalToSymbol[canonical]); 297 return kCanonicalToSymbol[canonical];
298 } 298 }
299 299
300 // TODO(jamessynge): Maybe further refactorings, including just passing in a 300 // TODO(jamessynge): Maybe further refactorings, including just passing in a
301 // SpdyStringPiece instead of an HpackInputStream, thus avoiding the PeekBits 301 // SpdyStringPiece instead of an HpackInputStream, thus avoiding the PeekBits
302 // calls, and also allowing us to separate the code into portions dealing with 302 // calls, and also allowing us to separate the code into portions dealing with
303 // long strings, and a later portion dealing with the last few bytes of strings. 303 // long strings, and a later portion dealing with the last few bytes of strings.
304 // TODO(jamessynge): Determine if that is worth it by adding some counters to 304 // TODO(jamessynge): Determine if that is worth it by adding some counters to
305 // measure the distribution of string sizes seen in practice. 305 // measure the distribution of string sizes seen in practice.
306 bool HpackHuffmanDecoder::DecodeString(HpackInputStream* in, SpdyString* out) { 306 bool HpackHuffmanDecoder::DecodeString(HpackInputStream* in, SpdyString* out) {
307 out->clear(); 307 out->clear();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // Get some more bits for decoding (up to 8). |peeked_success| is true 391 // Get some more bits for decoding (up to 8). |peeked_success| is true
392 // if we got any bits. 392 // if we got any bits.
393 peeked_success = in->PeekBits(&bits_available, &bits); 393 peeked_success = in->PeekBits(&bits_available, &bits);
394 } 394 }
395 DLOG_IF(WARNING, (VLOG_IS_ON(2) && bits_available < 32 && !peeked_success)) 395 DLOG_IF(WARNING, (VLOG_IS_ON(2) && bits_available < 32 && !peeked_success))
396 << "no more peeking possible"; 396 << "no more peeking possible";
397 } 397 }
398 } 398 }
399 399
400 } // namespace net 400 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/core/hpack/hpack_huffman_decoder.h ('k') | net/spdy/core/hpack/hpack_huffman_decoder_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698