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

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

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/base/buffer.h ('k') | webrtc/base/buffer_unittest.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 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 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 #include "webrtc/base/buffer.h" 11 #include "webrtc/base/buffer.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <utility> 14 #include <utility>
15 15
16 namespace rtc { 16 namespace rtc {
17 17
18 Buffer::Buffer() : size_(0), capacity_(0), data_(nullptr) { 18 Buffer::Buffer() : size_(0), capacity_(0), data_(nullptr) {
19 RTC_DCHECK(IsConsistent()); 19 RTC_DCHECK(IsConsistent());
20 } 20 }
21 21
22 Buffer::Buffer(const Buffer& buf) : Buffer(buf.data(), buf.size()) {
23 }
24
22 Buffer::Buffer(Buffer&& buf) 25 Buffer::Buffer(Buffer&& buf)
23 : size_(buf.size()), 26 : size_(buf.size()),
24 capacity_(buf.capacity()), 27 capacity_(buf.capacity()),
25 data_(std::move(buf.data_)) { 28 data_(std::move(buf.data_)) {
26 RTC_DCHECK(IsConsistent()); 29 RTC_DCHECK(IsConsistent());
27 buf.OnMovedFrom(); 30 buf.OnMovedFrom();
28 } 31 }
29 32
30 Buffer::Buffer(size_t size) : Buffer(size, size) { 33 Buffer::Buffer(size_t size) : Buffer(size, size) {
31 } 34 }
32 35
33 Buffer::Buffer(size_t size, size_t capacity) 36 Buffer::Buffer(size_t size, size_t capacity)
34 : size_(size), 37 : size_(size),
35 capacity_(std::max(size, capacity)), 38 capacity_(std::max(size, capacity)),
36 data_(new uint8_t[capacity_]) { 39 data_(new uint8_t[capacity_]) {
37 RTC_DCHECK(IsConsistent()); 40 RTC_DCHECK(IsConsistent());
38 } 41 }
39 42
40 // Note: The destructor works even if the buffer has been moved from. 43 // Note: The destructor works even if the buffer has been moved from.
41 Buffer::~Buffer() = default; 44 Buffer::~Buffer() = default;
42 45
43 }; // namespace rtc 46 }; // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/buffer.h ('k') | webrtc/base/buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698