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

Side by Side Diff: webrtc/base/buffer.h

Issue 1687833006: rtc::Buffer: Replace an internal rtc::scoped_ptr with std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 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/api/objc/RTCDataChannel.mm ('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
11 #ifndef WEBRTC_BASE_BUFFER_H_ 11 #ifndef WEBRTC_BASE_BUFFER_H_
12 #define WEBRTC_BASE_BUFFER_H_ 12 #define WEBRTC_BASE_BUFFER_H_
13 13
14 #include <algorithm> // std::swap (pre-C++11) 14 #include <algorithm> // std::swap (pre-C++11)
15 #include <cassert> 15 #include <cassert>
16 #include <cstring> 16 #include <cstring>
17 #include <memory>
17 #include <utility> // std::swap (C++11 and later) 18 #include <utility> // std::swap (C++11 and later)
18 19
20 #include "webrtc/base/constructormagic.h"
19 #include "webrtc/base/deprecation.h" 21 #include "webrtc/base/deprecation.h"
20 #include "webrtc/base/scoped_ptr.h"
21 22
22 namespace rtc { 23 namespace rtc {
23 24
24 namespace internal { 25 namespace internal {
25 26
26 // (Internal; please don't use outside this file.) ByteType<T>::t is int if T 27 // (Internal; please don't use outside this file.) ByteType<T>::t is int if T
27 // is uint8_t, int8_t, or char; otherwise, it's a compilation error. Use like 28 // is uint8_t, int8_t, or char; otherwise, it's a compilation error. Use like
28 // this: 29 // this:
29 // 30 //
30 // template <typename T, typename ByteType<T>::t = 0> 31 // template <typename T, typename ByteType<T>::t = 0>
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 size_ = size; 158 size_ = size;
158 } 159 }
159 160
160 // Ensure that the buffer size can be increased to at least capacity without 161 // Ensure that the buffer size can be increased to at least capacity without
161 // further reallocation. (Of course, this operation might need to reallocate 162 // further reallocation. (Of course, this operation might need to reallocate
162 // the buffer.) 163 // the buffer.)
163 void EnsureCapacity(size_t capacity) { 164 void EnsureCapacity(size_t capacity) {
164 assert(IsConsistent()); 165 assert(IsConsistent());
165 if (capacity <= capacity_) 166 if (capacity <= capacity_)
166 return; 167 return;
167 scoped_ptr<uint8_t[]> new_data(new uint8_t[capacity]); 168 std::unique_ptr<uint8_t[]> new_data(new uint8_t[capacity]);
168 std::memcpy(new_data.get(), data_.get(), size_); 169 std::memcpy(new_data.get(), data_.get(), size_);
169 data_ = std::move(new_data); 170 data_ = std::move(new_data);
170 capacity_ = capacity; 171 capacity_ = capacity;
171 assert(IsConsistent()); 172 assert(IsConsistent());
172 } 173 }
173 174
174 // b.Pass() does the same thing as std::move(b). 175 // b.Pass() does the same thing as std::move(b).
175 // Deprecated; remove in March 2016 (bug 5373). 176 // Deprecated; remove in March 2016 (bug 5373).
176 RTC_DEPRECATED Buffer&& Pass() { return DEPRECATED_Pass(); } 177 RTC_DEPRECATED Buffer&& Pass() { return DEPRECATED_Pass(); }
177 Buffer&& DEPRECATED_Pass() { 178 Buffer&& DEPRECATED_Pass() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 capacity_ = 0; 216 capacity_ = 0;
216 #else 217 #else
217 // Ensure that *this is always inconsistent, to provoke bugs. 218 // Ensure that *this is always inconsistent, to provoke bugs.
218 size_ = 1; 219 size_ = 1;
219 capacity_ = 0; 220 capacity_ = 0;
220 #endif 221 #endif
221 } 222 }
222 223
223 size_t size_; 224 size_t size_;
224 size_t capacity_; 225 size_t capacity_;
225 scoped_ptr<uint8_t[]> data_; 226 std::unique_ptr<uint8_t[]> data_;
226 }; 227 };
227 228
228 } // namespace rtc 229 } // namespace rtc
229 230
230 #endif // WEBRTC_BASE_BUFFER_H_ 231 #endif // WEBRTC_BASE_BUFFER_H_
OLDNEW
« no previous file with comments | « webrtc/api/objc/RTCDataChannel.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698