Index: webrtc/base/copyonwritebuffer.h |
diff --git a/webrtc/base/copyonwritebuffer.h b/webrtc/base/copyonwritebuffer.h |
index 108aaa19d7aae6aed91cda23bfe3f00a21183d0f..18a44381e0fa8dc1bd1a0ed2b1820954c63ad395 100644 |
--- a/webrtc/base/copyonwritebuffer.h |
+++ b/webrtc/base/copyonwritebuffer.h |
@@ -153,9 +153,11 @@ class CopyOnWriteBuffer { |
internal::BufferCompat<uint8_t, T>::value>::type* = nullptr> |
void SetData(const T* data, size_t size) { |
RTC_DCHECK(IsConsistent()); |
- if (!buffer_ || !buffer_->HasOneRef()) { |
- buffer_ = size > 0 ? new RefCountedObject<Buffer>(data, size) |
- : nullptr; |
+ if (!buffer_) { |
+ buffer_ = size > 0 ? new RefCountedObject<Buffer>(data, size) : nullptr; |
+ } else if (!buffer_->HasOneRef()) { |
+ buffer_ = new RefCountedObject<Buffer>( |
+ data, size, std::max(size, buffer_->capacity())); |
kwiberg-webrtc
2016/09/13 09:24:30
I don't think you need the std::max---the Buffer c
danilchap
2016/09/13 09:56:36
Done.
It is nicer without extra max.
|
} else { |
buffer_->SetData(data, size); |
} |
@@ -253,11 +255,14 @@ class CopyOnWriteBuffer { |
RTC_DCHECK(IsConsistent()); |
} |
- // Resets the buffer to zero size and capacity. |
+ // Resets the buffer to zero size without altering capacity. Works even if the |
+ // buffer has been moved from. |
void Clear() { |
- RTC_DCHECK(IsConsistent()); |
- if (!buffer_ || !buffer_->HasOneRef()) { |
- buffer_ = nullptr; |
+ if (!buffer_) |
+ return; |
+ |
+ if (!buffer_->HasOneRef()) { |
kwiberg-webrtc
2016/09/13 09:24:30
You can eliminate the negation if you swap the if
danilchap
2016/09/13 09:56:36
Done.
|
+ buffer_ = new RefCountedObject<Buffer>(0, buffer_->capacity()); |
} else { |
buffer_->Clear(); |
} |