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

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

Issue 1817753003: Revert of Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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/webrtcsession_unittest.cc ('k') | webrtc/base/buffer.cc » ('j') | 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 using t = decltype(F(static_cast<T*>(nullptr))); 43 using t = decltype(F(static_cast<T*>(nullptr)));
44 }; 44 };
45 45
46 } // namespace internal 46 } // namespace internal
47 47
48 // Basic buffer class, can be grown and shrunk dynamically. 48 // Basic buffer class, can be grown and shrunk dynamically.
49 // Unlike std::string/vector, does not initialize data when expanding capacity. 49 // Unlike std::string/vector, does not initialize data when expanding capacity.
50 class Buffer { 50 class Buffer {
51 public: 51 public:
52 Buffer(); // An empty buffer. 52 Buffer(); // An empty buffer.
53 Buffer(const Buffer& buf); // Copy size and contents of an existing buffer.
53 Buffer(Buffer&& buf); // Move contents from an existing buffer. 54 Buffer(Buffer&& buf); // Move contents from an existing buffer.
54 55
55 // Construct a buffer with the specified number of uninitialized bytes. 56 // Construct a buffer with the specified number of uninitialized bytes.
56 explicit Buffer(size_t size); 57 explicit Buffer(size_t size);
57 Buffer(size_t size, size_t capacity); 58 Buffer(size_t size, size_t capacity);
58 59
59 // Construct a buffer and copy the specified number of bytes into it. The 60 // Construct a buffer and copy the specified number of bytes into it. The
60 // source array may be (const) uint8_t*, int8_t*, or char*. 61 // source array may be (const) uint8_t*, int8_t*, or char*.
61 template <typename T, typename internal::ByteType<T>::t = 0> 62 template <typename T, typename internal::ByteType<T>::t = 0>
62 Buffer(const T* data, size_t size) 63 Buffer(const T* data, size_t size)
(...skipping 29 matching lines...) Expand all
92 size_t size() const { 93 size_t size() const {
93 RTC_DCHECK(IsConsistent()); 94 RTC_DCHECK(IsConsistent());
94 return size_; 95 return size_;
95 } 96 }
96 97
97 size_t capacity() const { 98 size_t capacity() const {
98 RTC_DCHECK(IsConsistent()); 99 RTC_DCHECK(IsConsistent());
99 return capacity_; 100 return capacity_;
100 } 101 }
101 102
103 Buffer& operator=(const Buffer& buf) {
104 if (&buf != this)
105 SetData(buf.data(), buf.size());
106 return *this;
107 }
108
102 Buffer& operator=(Buffer&& buf) { 109 Buffer& operator=(Buffer&& buf) {
103 RTC_DCHECK(IsConsistent()); 110 RTC_DCHECK(IsConsistent());
104 RTC_DCHECK(buf.IsConsistent()); 111 RTC_DCHECK(buf.IsConsistent());
105 size_ = buf.size_; 112 size_ = buf.size_;
106 capacity_ = buf.capacity_; 113 capacity_ = buf.capacity_;
107 data_ = std::move(buf.data_); 114 data_ = std::move(buf.data_);
108 buf.OnMovedFrom(); 115 buf.OnMovedFrom();
109 return *this; 116 return *this;
110 } 117 }
111 118
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 #else 273 #else
267 // Ensure that *this is always inconsistent, to provoke bugs. 274 // Ensure that *this is always inconsistent, to provoke bugs.
268 size_ = 1; 275 size_ = 1;
269 capacity_ = 0; 276 capacity_ = 0;
270 #endif 277 #endif
271 } 278 }
272 279
273 size_t size_; 280 size_t size_;
274 size_t capacity_; 281 size_t capacity_;
275 std::unique_ptr<uint8_t[]> data_; 282 std::unique_ptr<uint8_t[]> data_;
276
277 RTC_DISALLOW_COPY_AND_ASSIGN(Buffer);
278 }; 283 };
279 284
280 } // namespace rtc 285 } // namespace rtc
281 286
282 #endif // WEBRTC_BASE_BUFFER_H_ 287 #endif // WEBRTC_BASE_BUFFER_H_
OLDNEW
« no previous file with comments | « webrtc/api/webrtcsession_unittest.cc ('k') | webrtc/base/buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698