Index: webrtc/base/copyonwritebuffer.h |
diff --git a/webrtc/base/copyonwritebuffer.h b/webrtc/base/copyonwritebuffer.h |
index 72fb4eea53495a2575ee435efade9d182afd4a69..41d4090a869b20f35b3ca01eaffb8f795ff87869 100644 |
--- a/webrtc/base/copyonwritebuffer.h |
+++ b/webrtc/base/copyonwritebuffer.h |
@@ -162,6 +162,23 @@ class CopyOnWriteBuffer { |
RTC_DCHECK(IsConsistent()); |
} |
+ // Replace the contents of the buffer. Ensure capacity is at least |capacity|. |
+ template <typename T, |
+ typename std::enable_if< |
+ internal::BufferCompat<uint8_t, T>::value>::type* = nullptr> |
+ void SetData(const T* data, size_t size, size_t capacity) { |
kwiberg-webrtc
2016/09/09 08:55:13
Isn't this equivalent to calling
x.EnsureCapaci
danilchap
2016/09/09 11:21:17
1. SetData signatures mirror constructor signature
kwiberg-webrtc
2016/09/09 12:59:13
I'm not sure. You can always replace
Buffer buf
danilchap
2016/09/09 16:00:56
Yes, I'm wrong. it is not same. Buffer may benefit
|
+ RTC_DCHECK(IsConsistent()); |
+ capacity = std::max(size, capacity); |
+ if (!buffer_ || !buffer_->HasOneRef() || buffer_->capacity() < capacity) { |
+ buffer_ = capacity > 0 |
+ ? new RefCountedObject<Buffer>(data, size, capacity) |
+ : nullptr; |
+ } else { |
+ buffer_->SetData(data, size); |
+ } |
+ RTC_DCHECK(IsConsistent()); |
+ } |
+ |
template <typename T, |
size_t N, |
typename std::enable_if< |