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

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

Issue 2801603003: Add SpdyString alias for std::string in net/spdy. (Closed)
Patch Set: Created 3 years, 8 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 #include <memory>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/numerics/safe_conversions.h" 12 #include "base/numerics/safe_conversions.h"
13 #include "net/spdy/hpack/hpack_input_stream.h" 13 #include "net/spdy/hpack/hpack_input_stream.h"
14 #include "net/spdy/hpack/hpack_output_stream.h" 14 #include "net/spdy/hpack/hpack_output_stream.h"
15 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h" 15 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 using std::string;
20
21 namespace { 19 namespace {
22 20
23 // How many bits to index in the root decode table. 21 // How many bits to index in the root decode table.
24 const uint8_t kDecodeTableRootBits = 9; 22 const uint8_t kDecodeTableRootBits = 9;
25 // Maximum number of bits to index in successive decode tables. 23 // Maximum number of bits to index in successive decode tables.
26 const uint8_t kDecodeTableBranchBits = 6; 24 const uint8_t kDecodeTableBranchBits = 6;
27 25
28 bool SymbolLengthAndIdCompare(const HpackHuffmanSymbol& a, 26 bool SymbolLengthAndIdCompare(const HpackHuffmanSymbol& a,
29 const HpackHuffmanSymbol& b) { 27 const HpackHuffmanSymbol& b) {
30 if (a.length == b.length) { 28 if (a.length == b.length) {
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 257
260 bit_count += length_by_id_[symbol_id]; 258 bit_count += length_by_id_[symbol_id];
261 } 259 }
262 if (bit_count % 8 != 0) { 260 if (bit_count % 8 != 0) {
263 bit_count += 8 - bit_count % 8; 261 bit_count += 8 - bit_count % 8;
264 } 262 }
265 return bit_count / 8; 263 return bit_count / 8;
266 } 264 }
267 265
268 bool HpackHuffmanTable::GenericDecodeString(HpackInputStream* in, 266 bool HpackHuffmanTable::GenericDecodeString(HpackInputStream* in,
269 string* out) const { 267 SpdyString* out) const {
270 // Number of decode iterations required for a 32-bit code. 268 // Number of decode iterations required for a 32-bit code.
271 const int kDecodeIterations = static_cast<int>( 269 const int kDecodeIterations = static_cast<int>(
272 std::ceil((32.f - kDecodeTableRootBits) / kDecodeTableBranchBits)); 270 std::ceil((32.f - kDecodeTableRootBits) / kDecodeTableBranchBits));
273 271
274 out->clear(); 272 out->clear();
275 273
276 // Current input, stored in the high |bits_available| bits of |bits|. 274 // Current input, stored in the high |bits_available| bits of |bits|.
277 uint32_t bits = 0; 275 uint32_t bits = 0;
278 size_t bits_available = 0; 276 size_t bits_available = 0;
279 bool peeked_success = in->PeekBits(&bits_available, &bits); 277 bool peeked_success = in->PeekBits(&bits_available, &bits);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 317 }
320 318
321 size_t HpackHuffmanTable::EstimateMemoryUsage() const { 319 size_t HpackHuffmanTable::EstimateMemoryUsage() const {
322 return SpdyEstimateMemoryUsage(decode_tables_) + 320 return SpdyEstimateMemoryUsage(decode_tables_) +
323 SpdyEstimateMemoryUsage(decode_entries_) + 321 SpdyEstimateMemoryUsage(decode_entries_) +
324 SpdyEstimateMemoryUsage(code_by_id_) + 322 SpdyEstimateMemoryUsage(code_by_id_) +
325 SpdyEstimateMemoryUsage(length_by_id_); 323 SpdyEstimateMemoryUsage(length_by_id_);
326 } 324 }
327 325
328 } // namespace net 326 } // 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