| OLD | NEW |
| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 Buffer& operator=(const Buffer& buf) { | 97 Buffer& operator=(const Buffer& buf) { |
| 98 if (&buf != this) | 98 if (&buf != this) |
| 99 SetData(buf.data(), buf.size()); | 99 SetData(buf.data(), buf.size()); |
| 100 return *this; | 100 return *this; |
| 101 } | 101 } |
| 102 Buffer& operator=(Buffer&& buf) { | 102 Buffer& operator=(Buffer&& buf) { |
| 103 assert(IsConsistent()); | 103 assert(IsConsistent()); |
| 104 assert(buf.IsConsistent()); | 104 assert(buf.IsConsistent()); |
| 105 size_ = buf.size_; | 105 size_ = buf.size_; |
| 106 capacity_ = buf.capacity_; | 106 capacity_ = buf.capacity_; |
| 107 data_ = buf.data_.Pass(); | 107 data_ = std::move(buf.data_); |
| 108 buf.OnMovedFrom(); | 108 buf.OnMovedFrom(); |
| 109 return *this; | 109 return *this; |
| 110 } | 110 } |
| 111 | 111 |
| 112 bool operator==(const Buffer& buf) const { | 112 bool operator==(const Buffer& buf) const { |
| 113 assert(IsConsistent()); | 113 assert(IsConsistent()); |
| 114 return size_ == buf.size() && memcmp(data_.get(), buf.data(), size_) == 0; | 114 return size_ == buf.size() && memcmp(data_.get(), buf.data(), size_) == 0; |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool operator!=(const Buffer& buf) const { return !(*this == buf); } | 117 bool operator!=(const Buffer& buf) const { return !(*this == buf); } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 157 |
| 158 // Ensure that the buffer size can be increased to at least capacity without | 158 // Ensure that the buffer size can be increased to at least capacity without |
| 159 // further reallocation. (Of course, this operation might need to reallocate | 159 // further reallocation. (Of course, this operation might need to reallocate |
| 160 // the buffer.) | 160 // the buffer.) |
| 161 void EnsureCapacity(size_t capacity) { | 161 void EnsureCapacity(size_t capacity) { |
| 162 assert(IsConsistent()); | 162 assert(IsConsistent()); |
| 163 if (capacity <= capacity_) | 163 if (capacity <= capacity_) |
| 164 return; | 164 return; |
| 165 scoped_ptr<uint8_t[]> new_data(new uint8_t[capacity]); | 165 scoped_ptr<uint8_t[]> new_data(new uint8_t[capacity]); |
| 166 std::memcpy(new_data.get(), data_.get(), size_); | 166 std::memcpy(new_data.get(), data_.get(), size_); |
| 167 data_ = new_data.Pass(); | 167 data_ = std::move(new_data); |
| 168 capacity_ = capacity; | 168 capacity_ = capacity; |
| 169 assert(IsConsistent()); | 169 assert(IsConsistent()); |
| 170 } | 170 } |
| 171 | 171 |
| 172 // We can't call std::move(b), so call b.Pass() instead to do the same job. | 172 // b.Pass() does the same thing as std::move(b). |
| 173 Buffer&& Pass() { | 173 Buffer&& Pass() { |
| 174 assert(IsConsistent()); | 174 assert(IsConsistent()); |
| 175 return static_cast<Buffer&&>(*this); | 175 return static_cast<Buffer&&>(*this); |
| 176 } | 176 } |
| 177 | 177 |
| 178 // Resets the buffer to zero size and capacity. Works even if the buffer has | 178 // Resets the buffer to zero size and capacity. Works even if the buffer has |
| 179 // been moved from. | 179 // been moved from. |
| 180 void Clear() { | 180 void Clear() { |
| 181 data_.reset(); | 181 data_.reset(); |
| 182 size_ = 0; | 182 size_ = 0; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 } | 217 } |
| 218 | 218 |
| 219 size_t size_; | 219 size_t size_; |
| 220 size_t capacity_; | 220 size_t capacity_; |
| 221 scoped_ptr<uint8_t[]> data_; | 221 scoped_ptr<uint8_t[]> data_; |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 } // namespace rtc | 224 } // namespace rtc |
| 225 | 225 |
| 226 #endif // WEBRTC_BASE_BUFFER_H_ | 226 #endif // WEBRTC_BASE_BUFFER_H_ |
| OLD | NEW |