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

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

Issue 2338843002: Move CopyOnWriteBuffer functions definitions from .h to .cc (Closed)
Patch Set: Created 4 years, 3 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/copyonwritebuffer.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 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 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 20 matching lines...) Expand all
31 31
32 CopyOnWriteBuffer::CopyOnWriteBuffer(size_t size, size_t capacity) 32 CopyOnWriteBuffer::CopyOnWriteBuffer(size_t size, size_t capacity)
33 : buffer_(size > 0 || capacity > 0 33 : buffer_(size > 0 || capacity > 0
34 ? new RefCountedObject<Buffer>(size, capacity) 34 ? new RefCountedObject<Buffer>(size, capacity)
35 : nullptr) { 35 : nullptr) {
36 RTC_DCHECK(IsConsistent()); 36 RTC_DCHECK(IsConsistent());
37 } 37 }
38 38
39 CopyOnWriteBuffer::~CopyOnWriteBuffer() = default; 39 CopyOnWriteBuffer::~CopyOnWriteBuffer() = default;
40 40
41 bool CopyOnWriteBuffer::operator==(const CopyOnWriteBuffer& buf) const {
42 // Must either use the same buffer internally or have the same contents.
43 RTC_DCHECK(IsConsistent());
44 RTC_DCHECK(buf.IsConsistent());
45 return buffer_.get() == buf.buffer_.get() ||
46 (buffer_.get() && buf.buffer_.get() &&
47 *buffer_.get() == *buf.buffer_.get());
48 }
49
50 void CopyOnWriteBuffer::SetSize(size_t size) {
51 RTC_DCHECK(IsConsistent());
52 if (!buffer_) {
53 if (size > 0) {
54 buffer_ = new RefCountedObject<Buffer>(size);
55 }
56 RTC_DCHECK(IsConsistent());
57 return;
58 }
59
60 // Clone data if referenced.
61 if (!buffer_->HasOneRef()) {
62 buffer_ = new RefCountedObject<Buffer>(
63 buffer_->data(),
64 std::min(buffer_->size(), size),
65 std::max(buffer_->capacity(), size));
66 }
67 buffer_->SetSize(size);
68 RTC_DCHECK(IsConsistent());
69 }
70
71 void CopyOnWriteBuffer::EnsureCapacity(size_t capacity) {
72 RTC_DCHECK(IsConsistent());
73 if (!buffer_) {
74 if (capacity > 0) {
75 buffer_ = new RefCountedObject<Buffer>(0, capacity);
76 }
77 RTC_DCHECK(IsConsistent());
78 return;
79 } else if (capacity <= buffer_->capacity()) {
80 return;
81 }
82
83 CloneDataIfReferenced(std::max(buffer_->capacity(), capacity));
84 buffer_->EnsureCapacity(capacity);
85 RTC_DCHECK(IsConsistent());
86 }
87
88 void CopyOnWriteBuffer::Clear() {
89 if (!buffer_)
90 return;
91
92 if (buffer_->HasOneRef()) {
93 buffer_->Clear();
94 } else {
95 buffer_ = new RefCountedObject<Buffer>(0, buffer_->capacity());
96 }
97 RTC_DCHECK(IsConsistent());
98 }
99
100 void CopyOnWriteBuffer::CloneDataIfReferenced(size_t new_capacity) {
101 if (buffer_->HasOneRef()) {
102 return;
103 }
104
105 buffer_ = new RefCountedObject<Buffer>(buffer_->data(), buffer_->size(),
106 new_capacity);
107 RTC_DCHECK(IsConsistent());
108 }
109
110
111
41 } // namespace rtc 112 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/copyonwritebuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698