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

Side by Side Diff: net/base/arena.cc

Issue 2611173004: Modify SpdyHeaderBlock's internals to consolidate header values only on first access. (Closed)
Patch Set: Rebase. Created 3 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/base/arena.h ('k') | net/spdy/spdy_header_block.h » ('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 (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #include "net/base/arena.h" 5 #include "net/base/arena.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 Block& b = blocks_.back(); 61 Block& b = blocks_.back();
62 if (size <= b.used && data + size == b.data.get() + b.used) { 62 if (size <= b.used && data + size == b.data.get() + b.used) {
63 // The memory region passed by the caller was the most recent allocation 63 // The memory region passed by the caller was the most recent allocation
64 // from the final block in this arena. 64 // from the final block in this arena.
65 b.used -= size; 65 b.used -= size;
66 } 66 }
67 } 67 }
68 68
69 void UnsafeArena::Reset() { 69 void UnsafeArena::Reset() {
70 blocks_.clear(); 70 blocks_.clear();
71 status_.bytes_allocated_ = 0;
71 } 72 }
72 73
73 void UnsafeArena::Reserve(size_t additional_space) { 74 void UnsafeArena::Reserve(size_t additional_space) {
74 if (blocks_.empty()) { 75 if (blocks_.empty()) {
75 AllocBlock(std::max(additional_space, block_size_)); 76 AllocBlock(std::max(additional_space, block_size_));
76 } else { 77 } else {
77 const Block& last = blocks_.back(); 78 const Block& last = blocks_.back();
78 if (last.size < last.used + additional_space) { 79 if (last.size < last.used + additional_space) {
79 AllocBlock(std::max(additional_space, block_size_)); 80 AllocBlock(std::max(additional_space, block_size_));
80 } 81 }
81 } 82 }
82 } 83 }
83 84
84 void UnsafeArena::AllocBlock(size_t size) { 85 void UnsafeArena::AllocBlock(size_t size) {
85 blocks_.push_back(Block(size)); 86 blocks_.push_back(Block(size));
87 status_.bytes_allocated_ += size;
86 } 88 }
87 89
88 UnsafeArena::Block::Block(size_t s) : data(new char[s]), size(s), used(0) {} 90 UnsafeArena::Block::Block(size_t s) : data(new char[s]), size(s), used(0) {}
89 91
90 UnsafeArena::Block::~Block() {} 92 UnsafeArena::Block::~Block() {}
91 93
92 UnsafeArena::Block::Block(UnsafeArena::Block&& other) 94 UnsafeArena::Block::Block(UnsafeArena::Block&& other)
93 : size(other.size), used(other.used) { 95 : size(other.size), used(other.used) {
94 data = std::move(other.data); 96 data = std::move(other.data);
95 } 97 }
96 98
97 UnsafeArena::Block& UnsafeArena::Block::operator=(UnsafeArena::Block&& other) { 99 UnsafeArena::Block& UnsafeArena::Block::operator=(UnsafeArena::Block&& other) {
98 size = other.size; 100 size = other.size;
99 used = other.used; 101 used = other.used;
100 data = std::move(other.data); 102 data = std::move(other.data);
101 return *this; 103 return *this;
102 } 104 }
103 105
104 } // namespace net 106 } // namespace net
OLDNEW
« no previous file with comments | « net/base/arena.h ('k') | net/spdy/spdy_header_block.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698