From 5e1a7496bbf46dde3e61f58de32bbc3b889546da Mon Sep 17 00:00:00 2001 From: Oskar Sundbom Date: Thu, 16 Nov 2017 10:57:19 +0100 Subject: [PATCH] Optional: Use nullopt and implicit construction in /common_audio 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=tina.legrand@webrtc.org Bug: None Change-Id: Iea6f04db7c1f92fe9da2c855bb60ad2f70c371d3 Reviewed-on: https://webrtc-review.googlesource.com/23615 Reviewed-by: Karl Wiberg Commit-Queue: Oskar Sundbom Cr-Commit-Position: refs/heads/master@{#20915} --- common_audio/smoothing_filter.cc | 6 +++--- common_audio/smoothing_filter_unittest.cc | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/common_audio/smoothing_filter.cc b/common_audio/smoothing_filter.cc index 41085a4760..ecfb5c252b 100644 --- a/common_audio/smoothing_filter.cc +++ b/common_audio/smoothing_filter.cc @@ -43,7 +43,7 @@ void SmoothingFilterImpl::AddSample(float sample) { // This is equivalent to assuming the filter has been receiving the same // value as the first sample since time -infinity. state_ = last_sample_ = sample; - init_end_time_ms_ = rtc::Optional(now_ms + init_time_ms_); + init_end_time_ms_ = now_ms + init_time_ms_; last_state_time_ms_ = now_ms; return; } @@ -55,10 +55,10 @@ void SmoothingFilterImpl::AddSample(float sample) { rtc::Optional SmoothingFilterImpl::GetAverage() { if (!init_end_time_ms_) { // |init_end_time_ms_| undefined since we have not received any sample. - return rtc::Optional(); + return rtc::nullopt; } ExtrapolateLastSample(rtc::TimeMillis()); - return rtc::Optional(state_); + return state_; } bool SmoothingFilterImpl::SetTimeConstantMs(int time_constant_ms) { diff --git a/common_audio/smoothing_filter_unittest.cc b/common_audio/smoothing_filter_unittest.cc index 9d93d6d4a5..d173c9ab85 100644 --- a/common_audio/smoothing_filter_unittest.cc +++ b/common_audio/smoothing_filter_unittest.cc @@ -132,8 +132,7 @@ TEST(SmoothingFilterTest, GetAverageOutputsEmptyBeforeFirstSample) { EXPECT_FALSE(states.smoothing_filter.GetAverage()); constexpr float kFirstSample = 1.2345f; states.smoothing_filter.AddSample(kFirstSample); - EXPECT_EQ(rtc::Optional(kFirstSample), - states.smoothing_filter.GetAverage()); + EXPECT_EQ(kFirstSample, states.smoothing_filter.GetAverage()); } TEST(SmoothingFilterTest, CannotChangeTimeConstantDuringInitialization) {