Delete mutable rtc::CopyOnWriteBuffer::data

Bug: webrtc:12334
Change-Id: I8798248dc591c5b69ff9434e7afc76ed2c7b02cc
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/201205
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33053}
This commit is contained in:
Danil Chapovalov 2021-01-21 17:00:16 +01:00 committed by Commit Bot
parent 6031b74664
commit e4fd1ba319
2 changed files with 15 additions and 42 deletions

View file

@ -95,14 +95,6 @@ class RTC_EXPORT CopyOnWriteBuffer {
return buffer_->data<T>() + offset_;
}
// TODO(bugs.webrtc.org/12334): Delete when all usage updated to MutableData()
template <typename T = uint8_t,
typename std::enable_if<
internal::BufferCompat<uint8_t, T>::value>::type* = nullptr>
T* data() {
return MutableData<T>();
}
// Get const pointer to the data. This will not create a copy of the
// underlying data if it is shared with other buffers.
template <typename T = uint8_t,
@ -154,12 +146,6 @@ class RTC_EXPORT CopyOnWriteBuffer {
return !(*this == buf);
}
// TODO(bugs.webrtc.org/12334): Delete when all usage updated to MutableData()
uint8_t& operator[](size_t index) {
RTC_DCHECK_LT(index, size());
return MutableData()[index];
}
uint8_t operator[](size_t index) const {
RTC_DCHECK_LT(index, size());
return cdata()[index];

View file

@ -261,47 +261,34 @@ TEST(CopyOnWriteBufferTest, ClearDoesntChangeCapacity) {
EXPECT_EQ(10u, buf2.capacity());
}
TEST(CopyOnWriteBufferTest, TestConstDataAccessor) {
TEST(CopyOnWriteBufferTest, DataAccessorDoesntCloneData) {
CopyOnWriteBuffer buf1(kTestData, 3, 10);
CopyOnWriteBuffer buf2(buf1);
// .cdata() doesn't clone data.
const uint8_t* cdata1 = buf1.cdata();
const uint8_t* cdata2 = buf2.cdata();
EXPECT_EQ(cdata1, cdata2);
// Non-const .data() clones data if shared.
const uint8_t* data1 = buf1.data();
const uint8_t* data2 = buf2.data();
EXPECT_NE(data1, data2);
// buf1 was cloned above.
EXPECT_NE(data1, cdata1);
// Therefore buf2 was no longer sharing data and was not cloned.
EXPECT_EQ(data2, cdata1);
EXPECT_EQ(buf1.data(), buf2.data());
}
TEST(CopyOnWriteBufferTest, MutableDataClonesDataWhenShared) {
CopyOnWriteBuffer buf1(kTestData, 3, 10);
CopyOnWriteBuffer buf2(buf1);
const uint8_t* cdata = buf1.data();
uint8_t* data1 = buf1.MutableData();
uint8_t* data2 = buf2.MutableData();
// buf1 was cloned above.
EXPECT_NE(data1, cdata);
// Therefore buf2 was no longer sharing data and was not cloned.
EXPECT_EQ(data2, cdata);
}
// TODO(bugs.webrtc.org/12334): Delete when all reads become const
TEST(CopyOnWriteBufferTest, SeveralReads) {
CopyOnWriteBuffer buf1(kTestData, 3, 10);
CopyOnWriteBuffer buf2(buf1);
EnsureBuffersShareData(buf1, buf2);
// Non-const reads clone the data if shared.
for (size_t i = 0; i != 3u; ++i) {
EXPECT_EQ(buf1[i], kTestData[i]);
}
EnsureBuffersDontShareData(buf1, buf2);
}
TEST(CopyOnWriteBufferTest, SeveralConstReads) {
CopyOnWriteBuffer buf1(kTestData, 3, 10);
CopyOnWriteBuffer buf2(buf1);
EnsureBuffersShareData(buf1, buf2);
const CopyOnWriteBuffer& cbuf1 = buf1;
for (size_t i = 0; i != 3u; ++i) {
EXPECT_EQ(cbuf1[i], kTestData[i]);
}
EnsureBuffersShareData(buf1, buf2);
}