From 903dcd733a84f8e48deb8fa4efee137a3eec64ea Mon Sep 17 00:00:00 2001 From: Oskar Sundbom Date: Thu, 16 Nov 2017 10:55:57 +0100 Subject: [PATCH] Optional: Use nullopt and implicit construction in /p2p 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. Bug: None Change-Id: Ia65be19b24c93db360a313f82a84bfae1a49bf2d Reviewed-on: https://webrtc-review.googlesource.com/23605 Reviewed-by: Karl Wiberg Commit-Queue: Oskar Sundbom Cr-Commit-Position: refs/heads/master@{#20929} --- p2p/base/fakeicetransport.h | 4 +--- p2p/base/mockicetransport.h | 4 +--- p2p/base/p2ptransportchannel.cc | 7 +++---- p2p/base/p2ptransportchannel_unittest.cc | 8 ++++---- p2p/base/port.cc | 3 +-- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/p2p/base/fakeicetransport.h b/p2p/base/fakeicetransport.h index ea730c32bb..236288ab0e 100644 --- a/p2p/base/fakeicetransport.h +++ b/p2p/base/fakeicetransport.h @@ -151,9 +151,7 @@ class FakeIceTransport : public IceTransportInternal { return true; } - rtc::Optional GetRttEstimate() override { - return rtc::Optional(); - } + rtc::Optional GetRttEstimate() override { return rtc::nullopt; } void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override { } diff --git a/p2p/base/mockicetransport.h b/p2p/base/mockicetransport.h index 4ea1869370..c77f8b1ba6 100644 --- a/p2p/base/mockicetransport.h +++ b/p2p/base/mockicetransport.h @@ -57,9 +57,7 @@ class MockIceTransport : public IceTransportInternal { void SetRemoteIceParameters(const IceParameters& ice_params) override {} void SetRemoteIceMode(IceMode mode) override {} void SetIceConfig(const IceConfig& config) override {} - rtc::Optional GetRttEstimate() override { - return rtc::Optional(); - } + rtc::Optional GetRttEstimate() override { return rtc::nullopt; } void MaybeStartGathering() override {} void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) override { } diff --git a/p2p/base/p2ptransportchannel.cc b/p2p/base/p2ptransportchannel.cc index 19abf38dcb..3f732e987d 100644 --- a/p2p/base/p2ptransportchannel.cc +++ b/p2p/base/p2ptransportchannel.cc @@ -307,9 +307,9 @@ IceGatheringState P2PTransportChannel::gathering_state() const { rtc::Optional P2PTransportChannel::GetRttEstimate() { if (selected_connection_ != nullptr && selected_connection_->rtt_samples() > 0) { - return rtc::Optional(selected_connection_->rtt()); + return selected_connection_->rtt(); } else { - return rtc::Optional(); + return rtc::nullopt; } } @@ -1340,8 +1340,7 @@ void P2PTransportChannel::SortConnectionsAndUpdateState() { // TODO(honghaiz): Don't sort; Just use std::max_element in the right places. std::stable_sort(connections_.begin(), connections_.end(), [this](const Connection* a, const Connection* b) { - int cmp = CompareConnections( - a, b, rtc::Optional(), nullptr); + int cmp = CompareConnections(a, b, rtc::nullopt, nullptr); if (cmp != 0) { return cmp > 0; } diff --git a/p2p/base/p2ptransportchannel_unittest.cc b/p2p/base/p2ptransportchannel_unittest.cc index 37f68073e1..e585b26f6c 100644 --- a/p2p/base/p2ptransportchannel_unittest.cc +++ b/p2p/base/p2ptransportchannel_unittest.cc @@ -1336,9 +1336,9 @@ TEST_F(P2PTransportChannelTest, // ep1 gathers continually but ep2 does not. IceConfig config1 = CreateIceConfig(1000, GATHER_CONTINUALLY); - config1.regather_on_failed_networks_interval = rtc::Optional(2000); + config1.regather_on_failed_networks_interval = 2000; IceConfig config2; - config2.regather_on_failed_networks_interval = rtc::Optional(2000); + config2.regather_on_failed_networks_interval = 2000; CreateChannels(config1, config2); EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && @@ -3013,7 +3013,7 @@ TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) { // Create channels and let them go writable, as usual. IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); - config.regather_on_failed_networks_interval = rtc::Optional(2000); + config.regather_on_failed_networks_interval = 2000; CreateChannels(config, config); EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && ep2_ch1()->receiving() && @@ -4132,7 +4132,7 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { P2PTransportChannel ch("test channel", 1, &pa); PrepareChannel(&ch); IceConfig config = CreateIceConfig(1000, GATHER_ONCE); - config.receiving_switching_delay = rtc::Optional(800); + config.receiving_switching_delay = 800; ch.SetIceConfig(config); ch.MaybeStartGathering(); ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); diff --git a/p2p/base/port.cc b/p2p/base/port.cc index 4421db2a2e..3bbc1e7f04 100644 --- a/p2p/base/port.cc +++ b/p2p/base/port.cc @@ -1330,8 +1330,7 @@ void Connection::ReceivedPingResponse(int rtt, const std::string& request_id) { } total_round_trip_time_ms_ += rtt; - current_round_trip_time_ms_ = rtc::Optional( - static_cast(rtt)); + current_round_trip_time_ms_ = static_cast(rtt); pings_since_last_response_.clear(); last_ping_response_received_ = rtc::TimeMillis();