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

Side by Side Diff: webrtc/base/bytebuffer.cc

Issue 2440083002: Delete always-zero ByteBufferWriter::start_. (Closed)
Patch Set: Delete useless memmove. Created 4 years, 2 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 | « webrtc/base/bytebuffer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 25 matching lines...) Expand all
36 Construct(bytes, len); 36 Construct(bytes, len);
37 } 37 }
38 38
39 ByteBufferWriter::ByteBufferWriter(const char* bytes, size_t len, 39 ByteBufferWriter::ByteBufferWriter(const char* bytes, size_t len,
40 ByteOrder byte_order) 40 ByteOrder byte_order)
41 : ByteBuffer(byte_order) { 41 : ByteBuffer(byte_order) {
42 Construct(bytes, len); 42 Construct(bytes, len);
43 } 43 }
44 44
45 void ByteBufferWriter::Construct(const char* bytes, size_t len) { 45 void ByteBufferWriter::Construct(const char* bytes, size_t len) {
46 start_ = 0;
47 size_ = len; 46 size_ = len;
48 bytes_ = new char[size_]; 47 bytes_ = new char[size_];
49 48
50 if (bytes) { 49 if (bytes) {
51 end_ = len; 50 end_ = len;
52 memcpy(bytes_, bytes, end_); 51 memcpy(bytes_, bytes, end_);
53 } else { 52 } else {
54 end_ = 0; 53 end_ = 0;
55 } 54 }
56 } 55 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 char* ByteBufferWriter::ReserveWriteBuffer(size_t len) { 111 char* ByteBufferWriter::ReserveWriteBuffer(size_t len) {
113 if (Length() + len > Capacity()) 112 if (Length() + len > Capacity())
114 Resize(Length() + len); 113 Resize(Length() + len);
115 114
116 char* start = bytes_ + end_; 115 char* start = bytes_ + end_;
117 end_ += len; 116 end_ += len;
118 return start; 117 return start;
119 } 118 }
120 119
121 void ByteBufferWriter::Resize(size_t size) { 120 void ByteBufferWriter::Resize(size_t size) {
122 size_t len = std::min(end_ - start_, size); 121 size_t len = std::min(end_, size);
123 if (size <= size_) { 122 if (size > size_) {
124 // Don't reallocate, just move data backwards
125 memmove(bytes_, bytes_ + start_, len);
126 } else {
127 // Reallocate a larger buffer. 123 // Reallocate a larger buffer.
128 size_ = std::max(size, 3 * size_ / 2); 124 size_ = std::max(size, 3 * size_ / 2);
129 char* new_bytes = new char[size_]; 125 char* new_bytes = new char[size_];
130 memcpy(new_bytes, bytes_ + start_, len); 126 memcpy(new_bytes, bytes_, len);
131 delete [] bytes_; 127 delete [] bytes_;
132 bytes_ = new_bytes; 128 bytes_ = new_bytes;
133 } 129 }
134 start_ = 0;
135 end_ = len; 130 end_ = len;
136 } 131 }
137 132
138 void ByteBufferWriter::Clear() { 133 void ByteBufferWriter::Clear() {
139 memset(bytes_, 0, size_); 134 memset(bytes_, 0, size_);
140 start_ = end_ = 0; 135 end_ = 0;
141 } 136 }
142 137
143 138
144 ByteBufferReader::ByteBufferReader(const char* bytes, size_t len) 139 ByteBufferReader::ByteBufferReader(const char* bytes, size_t len)
145 : ByteBuffer(ORDER_NETWORK) { 140 : ByteBuffer(ORDER_NETWORK) {
146 Construct(bytes, len); 141 Construct(bytes, len);
147 } 142 }
148 143
149 ByteBufferReader::ByteBufferReader(const char* bytes, size_t len, 144 ByteBufferReader::ByteBufferReader(const char* bytes, size_t len,
150 ByteOrder byte_order) 145 ByteOrder byte_order)
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 274 }
280 275
281 bool ByteBufferReader::Consume(size_t size) { 276 bool ByteBufferReader::Consume(size_t size) {
282 if (size > Length()) 277 if (size > Length())
283 return false; 278 return false;
284 start_ += size; 279 start_ += size;
285 return true; 280 return true;
286 } 281 }
287 282
288 } // namespace rtc 283 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/bytebuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698