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

Side by Side Diff: net/spdy/hpack/hpack_huffman_table.cc

Issue 1568423002: Implement better HPACK Huffman code decoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Do not use binary literals. Created 4 years, 11 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
« no previous file with comments | « net/spdy/hpack/hpack_huffman_table.h ('k') | net/spdy/hpack/hpack_huffman_table_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "net/spdy/hpack/hpack_huffman_table.h" 5 #include "net/spdy/hpack/hpack_huffman_table.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <memory>
9 10
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/numerics/safe_conversions.h" 12 #include "base/numerics/safe_conversions.h"
12 #include "net/spdy/hpack/hpack_input_stream.h" 13 #include "net/spdy/hpack/hpack_input_stream.h"
13 #include "net/spdy/hpack/hpack_output_stream.h" 14 #include "net/spdy/hpack/hpack_output_stream.h"
14 15
15 namespace net { 16 namespace net {
16 17
17 using base::StringPiece; 18 using base::StringPiece;
18 using std::string; 19 using std::string;
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 CHECK_GT(code_by_id_.size(), symbol_id); 257 CHECK_GT(code_by_id_.size(), symbol_id);
257 258
258 bit_count += length_by_id_[symbol_id]; 259 bit_count += length_by_id_[symbol_id];
259 } 260 }
260 if (bit_count % 8 != 0) { 261 if (bit_count % 8 != 0) {
261 bit_count += 8 - bit_count % 8; 262 bit_count += 8 - bit_count % 8;
262 } 263 }
263 return bit_count / 8; 264 return bit_count / 8;
264 } 265 }
265 266
266 bool HpackHuffmanTable::DecodeString(HpackInputStream* in, 267 bool HpackHuffmanTable::GenericDecodeString(HpackInputStream* in,
267 size_t out_capacity, 268 size_t out_capacity,
268 string* out) const { 269 string* out) const {
269 // Number of decode iterations required for a 32-bit code. 270 // Number of decode iterations required for a 32-bit code.
270 const int kDecodeIterations = static_cast<int>( 271 const int kDecodeIterations = static_cast<int>(
271 std::ceil((32.f - kDecodeTableRootBits) / kDecodeTableBranchBits)); 272 std::ceil((32.f - kDecodeTableRootBits) / kDecodeTableBranchBits));
272 273
273 out->clear(); 274 out->clear();
274 275
275 // Current input, stored in the high |bits_available| bits of |bits|. 276 // Current input, stored in the high |bits_available| bits of |bits|.
276 uint32_t bits = 0; 277 uint32_t bits = 0;
277 size_t bits_available = 0; 278 size_t bits_available = 0;
278 bool peeked_success = in->PeekBits(&bits_available, &bits); 279 bool peeked_success = in->PeekBits(&bits_available, &bits);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 bits = bits << entry.length; 316 bits = bits << entry.length;
316 bits_available -= entry.length; 317 bits_available -= entry.length;
317 } 318 }
318 peeked_success = in->PeekBits(&bits_available, &bits); 319 peeked_success = in->PeekBits(&bits_available, &bits);
319 } 320 }
320 NOTREACHED(); 321 NOTREACHED();
321 return false; 322 return false;
322 } 323 }
323 324
324 } // namespace net 325 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/hpack/hpack_huffman_table.h ('k') | net/spdy/hpack/hpack_huffman_table_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698