From 5686e3457e3724893ae0d0f85edb8ac1e45b3b03 Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Wed, 16 Dec 2020 07:29:02 +0100 Subject: [PATCH] Optimize calls to std::string::find() and friends for a single char. The character literal overload is more efficient. No-Presubmit: True No-Try: True Bug: None Change-Id: Ice0b8478accd8a252ab81a0496d46c0f71db3db6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/197810 Commit-Queue: Mirko Bonadei Reviewed-by: Henrik Andreassson Cr-Commit-Position: refs/heads/master@{#32841} --- modules/audio_coding/neteq/tools/neteq_quality_test.cc | 2 +- p2p/base/stun_port_unittest.cc | 2 +- p2p/base/turn_port_unittest.cc | 2 +- test/frame_generator_capturer.cc | 2 +- test/scenario/video_stream.cc | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/audio_coding/neteq/tools/neteq_quality_test.cc b/modules/audio_coding/neteq/tools/neteq_quality_test.cc index 80e3be2f3f..3f3077f531 100644 --- a/modules/audio_coding/neteq/tools/neteq_quality_test.cc +++ b/modules/audio_coding/neteq/tools/neteq_quality_test.cc @@ -107,7 +107,7 @@ const int kPacketLossTimeUnitMs = 10; // Common validator for file names. static bool ValidateFilename(const std::string& value, bool is_output) { if (!is_output) { - RTC_CHECK_NE(value.substr(value.find_last_of(".") + 1), "wav") + RTC_CHECK_NE(value.substr(value.find_last_of('.') + 1), "wav") << "WAV file input is not supported"; } FILE* fid = diff --git a/p2p/base/stun_port_unittest.cc b/p2p/base/stun_port_unittest.cc index 0c428f200e..31542daccc 100644 --- a/p2p/base/stun_port_unittest.cc +++ b/p2p/base/stun_port_unittest.cc @@ -223,7 +223,7 @@ TEST_F(StunPortTest, TestPrepareAddressFail) { EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code, cricket::SERVER_NOT_REACHABLE_ERROR, kTimeoutMs, fake_clock); - ASSERT_NE(error_event_.error_text.find("."), std::string::npos); + ASSERT_NE(error_event_.error_text.find('.'), std::string::npos); ASSERT_NE(error_event_.address.find(kLocalAddr.HostAsSensitiveURIString()), std::string::npos); std::string server_url = "stun:" + kBadAddr.ToString(); diff --git a/p2p/base/turn_port_unittest.cc b/p2p/base/turn_port_unittest.cc index e8c9b5c8ad..e5f614e2d6 100644 --- a/p2p/base/turn_port_unittest.cc +++ b/p2p/base/turn_port_unittest.cc @@ -934,7 +934,7 @@ TEST_F(TurnPortTest, EXPECT_TRUE_SIMULATED_WAIT(turn_error_, kSimulatedRtt, fake_clock_); EXPECT_EQ_SIMULATED_WAIT(error_event_.error_code, STUN_ERROR_GLOBAL_FAILURE, kSimulatedRtt, fake_clock_); - ASSERT_NE(error_event_.error_text.find("."), std::string::npos); + ASSERT_NE(error_event_.error_text.find('.'), std::string::npos); ASSERT_NE(error_event_.address.find(kLocalAddr2.HostAsSensitiveURIString()), std::string::npos); ASSERT_NE(error_event_.port, 0); diff --git a/test/frame_generator_capturer.cc b/test/frame_generator_capturer.cc index 266cff8734..a4c528e0f7 100644 --- a/test/frame_generator_capturer.cc +++ b/test/frame_generator_capturer.cc @@ -31,7 +31,7 @@ namespace test { namespace { std::string TransformFilePath(std::string path) { static const std::string resource_prefix = "res://"; - int ext_pos = path.rfind("."); + int ext_pos = path.rfind('.'); if (ext_pos < 0) { return test::ResourcePath(path, "yuv"); } else if (absl::StartsWith(path, resource_prefix)) { diff --git a/test/scenario/video_stream.cc b/test/scenario/video_stream.cc index 3c368861d3..5525a9d203 100644 --- a/test/scenario/video_stream.cc +++ b/test/scenario/video_stream.cc @@ -110,7 +110,7 @@ std::vector GetVideoRtpExtensions( std::string TransformFilePath(std::string path) { static const std::string resource_prefix = "res://"; - int ext_pos = path.rfind("."); + int ext_pos = path.rfind('.'); if (ext_pos < 0) { return test::ResourcePath(path, "yuv"); } else if (absl::StartsWith(path, resource_prefix)) {