Optional: Use nullopt and implicit construction in /modules/audio_processing

Changes places where we explicitly construct an Optional to instead use
nullopt or the requisite value type only.

This CL was uploaded by git cl split.

R=henrik.lundin@webrtc.org

Bug: None
Change-Id: I733a83f702fe11884d229a1713cfac952727bde8
Reviewed-on: https://webrtc-review.googlesource.com/23601
Commit-Queue: Oskar Sundbom <ossu@webrtc.org>
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20786}
This commit is contained in:
Oskar Sundbom
2017-11-17 14:34:48 +01:00
committed by Commit Bot
parent 28dfeb7f24
commit aa8b67da9d
27 changed files with 124 additions and 147 deletions

View File

@ -30,14 +30,14 @@ void CircularBuffer::Push(float value) {
rtc::Optional<float> CircularBuffer::Pop() {
if (nr_elements_in_buffer_ == 0) {
return rtc::Optional<float>();
return rtc::nullopt;
}
const size_t index =
(buffer_.size() + next_insertion_index_ - nr_elements_in_buffer_) %
buffer_.size();
RTC_DCHECK_LT(index, buffer_.size());
--nr_elements_in_buffer_;
return rtc::Optional<float>(buffer_[index]);
return buffer_[index];
}
void CircularBuffer::Clear() {

View File

@ -17,8 +17,8 @@ TEST(CircularBufferTests, LessThanMaxTest) {
CircularBuffer test_buffer(3);
test_buffer.Push(1.f);
test_buffer.Push(2.f);
EXPECT_EQ(rtc::Optional<float>(1.f), test_buffer.Pop());
EXPECT_EQ(rtc::Optional<float>(2.f), test_buffer.Pop());
EXPECT_EQ(1.f, test_buffer.Pop());
EXPECT_EQ(2.f, test_buffer.Pop());
}
TEST(CircularBufferTests, FillTest) {
@ -26,9 +26,9 @@ TEST(CircularBufferTests, FillTest) {
test_buffer.Push(1.f);
test_buffer.Push(2.f);
test_buffer.Push(3.f);
EXPECT_EQ(rtc::Optional<float>(1.f), test_buffer.Pop());
EXPECT_EQ(rtc::Optional<float>(2.f), test_buffer.Pop());
EXPECT_EQ(rtc::Optional<float>(3.f), test_buffer.Pop());
EXPECT_EQ(1.f, test_buffer.Pop());
EXPECT_EQ(2.f, test_buffer.Pop());
EXPECT_EQ(3.f, test_buffer.Pop());
}
TEST(CircularBufferTests, OverflowTest) {
@ -39,14 +39,14 @@ TEST(CircularBufferTests, OverflowTest) {
test_buffer.Push(4.f);
// Because the circular buffer has a size of 3, the first insert should have
// been forgotten.
EXPECT_EQ(rtc::Optional<float>(2.f), test_buffer.Pop());
EXPECT_EQ(rtc::Optional<float>(3.f), test_buffer.Pop());
EXPECT_EQ(rtc::Optional<float>(4.f), test_buffer.Pop());
EXPECT_EQ(2.f, test_buffer.Pop());
EXPECT_EQ(3.f, test_buffer.Pop());
EXPECT_EQ(4.f, test_buffer.Pop());
}
TEST(CircularBufferTests, ReadFromEmpty) {
CircularBuffer test_buffer(3);
EXPECT_EQ(rtc::Optional<float>(), test_buffer.Pop());
EXPECT_EQ(rtc::nullopt, test_buffer.Pop());
}
} // namespace webrtc