Index: webrtc/base/copyonwritebuffer.h |
diff --git a/webrtc/base/copyonwritebuffer.h b/webrtc/base/copyonwritebuffer.h |
index 70833d6c62b7a50d778e64ca6f62eb43a2389905..fe3f5619d131fb428d3f71c78122a284baa1d8e6 100644 |
--- a/webrtc/base/copyonwritebuffer.h |
+++ b/webrtc/base/copyonwritebuffer.h |
@@ -123,14 +123,7 @@ class CopyOnWriteBuffer { |
return *this; |
} |
- bool operator==(const CopyOnWriteBuffer& buf) const { |
- // Must either use the same buffer internally or have the same contents. |
- RTC_DCHECK(IsConsistent()); |
- RTC_DCHECK(buf.IsConsistent()); |
- return buffer_.get() == buf.buffer_.get() || |
- (buffer_.get() && buf.buffer_.get() && |
- *buffer_.get() == *buf.buffer_.get()); |
- } |
+ bool operator==(const CopyOnWriteBuffer& buf) const; |
bool operator!=(const CopyOnWriteBuffer& buf) const { |
return !(*this == buf); |
@@ -213,60 +206,16 @@ class CopyOnWriteBuffer { |
// buffer contents will be kept but truncated; if the new size is greater, |
// the existing contents will be kept and the new space will be |
// uninitialized. |
- void SetSize(size_t size) { |
- RTC_DCHECK(IsConsistent()); |
- if (!buffer_) { |
- if (size > 0) { |
- buffer_ = new RefCountedObject<Buffer>(size); |
- } |
- RTC_DCHECK(IsConsistent()); |
- return; |
- } |
- |
- // Clone data if referenced. |
- if (!buffer_->HasOneRef()) { |
- buffer_ = new RefCountedObject<Buffer>( |
- buffer_->data(), |
- std::min(buffer_->size(), size), |
- std::max(buffer_->capacity(), size)); |
- } |
- buffer_->SetSize(size); |
- RTC_DCHECK(IsConsistent()); |
- } |
+ void SetSize(size_t size); |
// Ensure that the buffer size can be increased to at least capacity without |
// further reallocation. (Of course, this operation might need to reallocate |
// the buffer.) |
- void EnsureCapacity(size_t capacity) { |
- RTC_DCHECK(IsConsistent()); |
- if (!buffer_) { |
- if (capacity > 0) { |
- buffer_ = new RefCountedObject<Buffer>(0, capacity); |
- } |
- RTC_DCHECK(IsConsistent()); |
- return; |
- } else if (capacity <= buffer_->capacity()) { |
- return; |
- } |
- |
- CloneDataIfReferenced(std::max(buffer_->capacity(), capacity)); |
- buffer_->EnsureCapacity(capacity); |
- RTC_DCHECK(IsConsistent()); |
- } |
+ void EnsureCapacity(size_t capacity); |
// Resets the buffer to zero size without altering capacity. Works even if the |
// buffer has been moved from. |
- void Clear() { |
- if (!buffer_) |
- return; |
- |
- if (buffer_->HasOneRef()) { |
- buffer_->Clear(); |
- } else { |
- buffer_ = new RefCountedObject<Buffer>(0, buffer_->capacity()); |
- } |
- RTC_DCHECK(IsConsistent()); |
- } |
+ void Clear(); |
// Swaps two buffers. |
friend void swap(CopyOnWriteBuffer& a, CopyOnWriteBuffer& b) { |
@@ -276,15 +225,7 @@ class CopyOnWriteBuffer { |
private: |
// Create a copy of the underlying data if it is referenced from other Buffer |
// objects. |
- void CloneDataIfReferenced(size_t new_capacity) { |
- if (buffer_->HasOneRef()) { |
- return; |
- } |
- |
- buffer_ = new RefCountedObject<Buffer>(buffer_->data(), buffer_->size(), |
- new_capacity); |
- RTC_DCHECK(IsConsistent()); |
- } |
+ void CloneDataIfReferenced(size_t new_capacity); |
// Pre- and postcondition of all methods. |
bool IsConsistent() const { |