From e3d99221c416ea2f5a1675667be26c14327afc75 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Tue, 1 Mar 2016 01:57:38 -0800 Subject: [PATCH] rtc::Buffer: Use RTC_DCHECK instead of assert Review URL: https://codereview.webrtc.org/1749693002 Cr-Commit-Position: refs/heads/master@{#11826} --- webrtc/base/buffer.cc | 7 +++---- webrtc/base/buffer.h | 29 ++++++++++++++--------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/webrtc/base/buffer.cc b/webrtc/base/buffer.cc index d0965a34bf..3096cc92ba 100644 --- a/webrtc/base/buffer.cc +++ b/webrtc/base/buffer.cc @@ -11,13 +11,12 @@ #include "webrtc/base/buffer.h" #include -#include #include namespace rtc { Buffer::Buffer() : size_(0), capacity_(0), data_(nullptr) { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); } Buffer::Buffer(const Buffer& buf) : Buffer(buf.data(), buf.size()) { @@ -27,7 +26,7 @@ Buffer::Buffer(Buffer&& buf) : size_(buf.size()), capacity_(buf.capacity()), data_(std::move(buf.data_)) { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); buf.OnMovedFrom(); } @@ -38,7 +37,7 @@ Buffer::Buffer(size_t size, size_t capacity) : size_(size), capacity_(std::max(size, capacity)), data_(new uint8_t[capacity_]) { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); } // Note: The destructor works even if the buffer has been moved from. diff --git a/webrtc/base/buffer.h b/webrtc/base/buffer.h index 6fe9185446..e9c47ee84e 100644 --- a/webrtc/base/buffer.h +++ b/webrtc/base/buffer.h @@ -11,7 +11,6 @@ #ifndef WEBRTC_BASE_BUFFER_H_ #define WEBRTC_BASE_BUFFER_H_ -#include #include #include #include @@ -81,23 +80,23 @@ class Buffer { // but you may also use .data() and .data(). template ::t = 0> const T* data() const { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); return reinterpret_cast(data_.get()); } template ::t = 0> T* data() { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); return reinterpret_cast(data_.get()); } size_t size() const { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); return size_; } size_t capacity() const { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); return capacity_; } @@ -108,8 +107,8 @@ class Buffer { } Buffer& operator=(Buffer&& buf) { - assert(IsConsistent()); - assert(buf.IsConsistent()); + RTC_DCHECK(IsConsistent()); + RTC_DCHECK(buf.IsConsistent()); size_ = buf.size_; capacity_ = buf.capacity_; data_ = std::move(buf.data_); @@ -118,7 +117,7 @@ class Buffer { } bool operator==(const Buffer& buf) const { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); return size_ == buf.size() && memcmp(data_.get(), buf.data(), size_) == 0; } @@ -138,7 +137,7 @@ class Buffer { // same input types as the constructors. template ::t = 0> void SetData(const T* data, size_t size) { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); size_ = 0; AppendData(data, size); } @@ -169,12 +168,12 @@ class Buffer { // the same input types as the constructors. template ::t = 0> void AppendData(const T* data, size_t size) { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); const size_t new_size = size_ + size; EnsureCapacity(new_size); std::memcpy(data_.get() + size_, data, size); size_ = new_size; - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); } template ::t = 0> @@ -220,14 +219,14 @@ class Buffer { // further reallocation. (Of course, this operation might need to reallocate // the buffer.) void EnsureCapacity(size_t capacity) { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); if (capacity <= capacity_) return; std::unique_ptr new_data(new uint8_t[capacity]); std::memcpy(new_data.get(), data_.get(), size_); data_ = std::move(new_data); capacity_ = capacity; - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); } // b.Pass() does the same thing as std::move(b). @@ -235,7 +234,7 @@ class Buffer { RTC_DEPRECATED Buffer&& Pass() { return DEPRECATED_Pass(); } Buffer&& DEPRECATED_Pass() { - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); return std::move(*this); } @@ -243,7 +242,7 @@ class Buffer { // buffer has been moved from. void Clear() { size_ = 0; - assert(IsConsistent()); + RTC_DCHECK(IsConsistent()); } // Swaps two buffers. Also works for buffers that have been moved from.