OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/tools/flip_server/simple_buffer.h" | 5 #include "net/tools/flip_server/simple_buffer.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 | 7 |
8 // Some of the following member functions are marked inlined, even though they | 8 // Some of the following member functions are marked inlined, even though they |
9 // are virtual. This may seem counter-intuitive, since virtual functions are | 9 // are virtual. This may seem counter-intuitive, since virtual functions are |
10 // generally not eligible for inlining. Profiling results indicate that these | 10 // generally not eligible for inlining. Profiling results indicate that these |
(...skipping 19 matching lines...) Expand all Loading... |
30 SimpleBuffer::SimpleBuffer(int size) | 30 SimpleBuffer::SimpleBuffer(int size) |
31 : write_idx_(0), | 31 : write_idx_(0), |
32 read_idx_(0), | 32 read_idx_(0), |
33 storage_size_(size) { | 33 storage_size_(size) { |
34 // Callers may try to allocate overly large blocks, but negative sizes are | 34 // Callers may try to allocate overly large blocks, but negative sizes are |
35 // obviously wrong. | 35 // obviously wrong. |
36 CHECK_GE(size, 0); | 36 CHECK_GE(size, 0); |
37 storage_ = new char[size]; | 37 storage_ = new char[size]; |
38 } | 38 } |
39 | 39 |
| 40 SimpleBuffer::~SimpleBuffer() { |
| 41 delete[] storage_; |
| 42 } |
| 43 |
| 44 |
40 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
41 | 46 |
42 int SimpleBuffer::ReadableBytes() const { | 47 int SimpleBuffer::ReadableBytes() const { |
43 return write_idx_ - read_idx_; | 48 return write_idx_ - read_idx_; |
44 } | 49 } |
45 | 50 |
46 //////////////////////////////////////////////////////////////////////////////// | 51 //////////////////////////////////////////////////////////////////////////////// |
47 | 52 |
48 std::string SimpleBuffer::str() const { | 53 std::string SimpleBuffer::str() const { |
49 std::string s; | 54 std::string s; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 // amount of data specified here is expected to | 199 // amount of data specified here is expected to |
195 // already be resident (as if it was Written) | 200 // already be resident (as if it was Written) |
196 inline void SimpleBuffer::AdvanceWritablePtr(int amount_to_advance) { | 201 inline void SimpleBuffer::AdvanceWritablePtr(int amount_to_advance) { |
197 write_idx_ += amount_to_advance; | 202 write_idx_ += amount_to_advance; |
198 if (write_idx_ > storage_size_) { | 203 if (write_idx_ > storage_size_) { |
199 write_idx_ = storage_size_; | 204 write_idx_ = storage_size_; |
200 } | 205 } |
201 } | 206 } |
202 | 207 |
203 } // namespace net | 208 } // namespace net |
204 | |
OLD | NEW |