Index: webrtc/base/buffer.cc |
diff --git a/webrtc/base/buffer.cc b/webrtc/base/buffer.cc |
index 62855f1620dfeac0c9f797c96492cbf7a99404f1..f693b2a2f6da29ee42b15c713e8e9c23a7366c2a 100644 |
--- a/webrtc/base/buffer.cc |
+++ b/webrtc/base/buffer.cc |
@@ -8,25 +8,30 @@ |
* be found in the AUTHORS file in the root of the source tree. |
*/ |
-#include "webrtc/base/buffer.h" |
- |
-#include <cassert> |
#include <utility> |
+#include "webrtc/base/checks.h" |
+#include "webrtc/base/buffer.h" |
+ |
namespace rtc { |
-Buffer::Buffer() : size_(0), capacity_(0), data_(nullptr) { |
- assert(IsConsistent()); |
+Buffer::BufferData::BufferData(const void* data, size_t size, size_t capacity) |
+ : size_(size), |
+ capacity_(std::max(size, capacity)), |
+ data_(new uint8_t[capacity_]) { |
+ RTC_DCHECK(IsConsistent()); |
+ if (data && size) { |
+ std::memcpy(data_.get(), data, size); |
+ } |
+} |
+ |
+Buffer::Buffer() : data_(nullptr) { |
} |
-Buffer::Buffer(const Buffer& buf) : Buffer(buf.data(), buf.size()) { |
+Buffer::Buffer(const Buffer& buf) : data_(buf.data_) { |
} |
-Buffer::Buffer(Buffer&& buf) |
- : size_(buf.size()), |
- capacity_(buf.capacity()), |
- data_(std::move(buf.data_)) { |
- assert(IsConsistent()); |
+Buffer::Buffer(Buffer&& buf) : data_(std::move(buf.data_)) { |
kwiberg-webrtc
2016/02/15 12:33:16
If I'm reading things right, scoped_refptr isn't m
tommi
2016/02/15 14:56:51
scoped_refptr isn't movable, so this would leave t
kwiberg-webrtc
2016/02/15 15:05:03
Yeah, that's better. Introducing sharing is going
|
buf.OnMovedFrom(); |
} |
@@ -34,10 +39,8 @@ Buffer::Buffer(size_t size) : Buffer(size, size) { |
} |
Buffer::Buffer(size_t size, size_t capacity) |
- : size_(size), |
- capacity_(std::max(size, capacity)), |
- data_(new uint8_t[capacity_]) { |
- assert(IsConsistent()); |
+ : data_(new BufferData(nullptr, size, capacity)) { |
+ RTC_DCHECK(IsConsistent()); |
} |
// Note: The destructor works even if the buffer has been moved from. |