Skip to content

Commit

Permalink
Replace std::find with ContainsValue
Browse files Browse the repository at this point in the history
Source code is much easier to write:
if (ContainsKey(my_vector, my_search_value))
than:
if (std::find(my_vector.begin(), my_vector.end(), my_search_value)
 != my_vector.end())

Bug: 561800

Change-Id: Iff4275a102e98d51188b514ebf4df854243456dc
Reviewed-on: https://chromium-review.googlesource.com/1120450
Commit-Queue: Avi Drissman <avi@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#573776}
  • Loading branch information
qufehdquf9 authored and Commit Bot committed Jul 10, 2018
1 parent 3ca00ab commit c8433ab
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ Yoonjae Cho <yoonjae.cho92@gmail.com>
Yoshinori Sano <yoshinori.sano@gmail.com>
Youngho Seo <hazivoo@gmail.com>
Youngho Yoo <youngho33.yoo@lge.com>
Youngjin Choi <cyjin9.yc@gmail.com>
YoungKi Hong <simon.hong81@gmail.com>
Youngmin Yoo <youngmin.yoo@samsung.com>
Youngsoo Choi <kenshin.choi@samsung.com>
Expand Down
9 changes: 3 additions & 6 deletions content/browser/appcache/appcache_update_job_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -831,10 +831,8 @@ class AppCacheUpdateJobTest : public testing::TestWithParam<RequestHandlerType>,
expected = 2; // 2 hosts using frontend1
EXPECT_EQ(expected, events[0].first.size());
MockFrontend::HostIds& host_ids = events[0].first;
EXPECT_TRUE(std::find(host_ids.begin(), host_ids.end(), host1.host_id())
!= host_ids.end());
EXPECT_TRUE(std::find(host_ids.begin(), host_ids.end(), host3.host_id())
!= host_ids.end());
EXPECT_TRUE(base::ContainsValue(host_ids, host1.host_id()));
EXPECT_TRUE(base::ContainsValue(host_ids, host3.host_id()));
EXPECT_EQ(AppCacheEventID::APPCACHE_CHECKING_EVENT, events[0].second);

events = mock_frontend2.raised_events_;
Expand Down Expand Up @@ -3644,8 +3642,7 @@ class AppCacheUpdateJobTest : public testing::TestWithParam<RequestHandlerType>,

for (size_t k = 0; k < expected_ids.size(); ++k) {
int id = expected_ids[k];
EXPECT_TRUE(std::find(actual_ids.begin(), actual_ids.end(), id) !=
actual_ids.end());
EXPECT_TRUE(base::ContainsValue(actual_ids, id));
}
}

Expand Down
4 changes: 2 additions & 2 deletions content/browser/browsing_data/browsing_data_remover_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/stl_util.h"
#include "content/browser/browsing_data/storage_partition_http_cache_data_remover.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
Expand Down Expand Up @@ -67,8 +68,7 @@ bool DoesOriginMatchMaskAndURLs(

const std::vector<std::string>& schemes = url::GetWebStorageSchemes();
bool is_web_scheme =
(std::find(schemes.begin(), schemes.end(), origin.GetOrigin().scheme()) !=
schemes.end());
base::ContainsValue(schemes, origin.GetOrigin().scheme());

// If a websafe origin is unprotected, it matches iff UNPROTECTED_WEB.
if ((!policy || !policy->IsStorageProtected(origin.GetOrigin())) &&
Expand Down
6 changes: 3 additions & 3 deletions content/browser/frame_host/render_frame_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "base/metrics/user_metrics.h"
#include "base/numerics/safe_conversions.h"
#include "base/process/kill.h"
#include "base/stl_util.h"
#include "base/task_scheduler/post_task.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
Expand Down Expand Up @@ -1233,8 +1234,7 @@ bool RenderFrameHostImpl::SchemeShouldBypassCSP(
// TODO(arthursonzogni): url::GetBypassingCSPScheme() is used instead of the
// blink::SchemeRegistry. It contains 1) but not 2).
const auto& bypassing_schemes = url::GetCSPBypassingSchemes();
return std::find(bypassing_schemes.begin(), bypassing_schemes.end(),
scheme) != bypassing_schemes.end();
return base::ContainsValue(bypassing_schemes, scheme);
}

mojom::FrameInputHandler* RenderFrameHostImpl::GetFrameInputHandler() {
Expand Down Expand Up @@ -3690,7 +3690,7 @@ void RenderFrameHostImpl::CommitNavigation(
} else {
std::string scheme = common_params.url.scheme();
const auto& schemes = URLDataManagerBackend::GetWebUISchemes();
if (std::find(schemes.begin(), schemes.end(), scheme) != schemes.end()) {
if (base::ContainsValue(schemes, scheme)) {
network::mojom::URLLoaderFactoryPtr factory_for_webui =
CreateWebUIURLLoaderBinding(this, scheme);
if (enabled_bindings_ & kWebUIBindingsPolicyMask) {
Expand Down
3 changes: 2 additions & 1 deletion content/browser/loader/navigation_url_loader_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/bind_helpers.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/task_scheduler/post_task.h"
#include "base/trace_event/trace_event.h"
#include "components/download/public/common/download_stats.h"
Expand Down Expand Up @@ -1351,7 +1352,7 @@ NavigationURLLoaderImpl::NavigationURLLoaderImpl(
network::mojom::URLLoaderFactoryPtrInfo factory_for_webui;
const auto& schemes = URLDataManagerBackend::GetWebUISchemes();
std::string scheme = new_request->url.scheme();
if (std::find(schemes.begin(), schemes.end(), scheme) != schemes.end()) {
if (base::ContainsValue(schemes, scheme)) {
factory_for_webui = CreateWebUIURLLoaderBinding(
frame_tree_node->current_frame_host(), scheme)
.PassInterface();
Expand Down
4 changes: 2 additions & 2 deletions content/browser/media/midi_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/process/process.h"
#include "base/stl_util.h"
#include "base/trace_event/trace_event.h"
#include "content/browser/bad_message.h"
#include "content/browser/browser_main_loop.h"
Expand Down Expand Up @@ -108,8 +109,7 @@ void MidiHost::OnSendData(uint32_t port,
// Blink running in a renderer checks permission to raise a SecurityError
// in JavaScript. The actual permission check for security purposes
// happens here in the browser process.
if (!has_sys_ex_permission_ &&
std::find(data.begin(), data.end(), kSysExByte) != data.end()) {
if (!has_sys_ex_permission_ && base::ContainsValue(data, kSysExByte)) {
bad_message::ReceivedBadMessage(this, bad_message::MH_SYS_EX_PERMISSION);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion content/browser/webui/url_data_manager_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "base/memory/ref_counted_memory.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
Expand Down Expand Up @@ -63,7 +64,7 @@ const char kNetworkErrorKey[] = "netError";

bool SchemeIsInSchemes(const std::string& scheme,
const std::vector<std::string>& schemes) {
return std::find(schemes.begin(), schemes.end(), scheme) != schemes.end();
return base::ContainsValue(schemes, scheme);
}

// Returns a value of 'Origin:' header for the |request| if the header is set.
Expand Down
8 changes: 4 additions & 4 deletions content/public/browser/notification_registrar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <algorithm>

#include "base/logging.h"
#include "base/stl_util.h"
#include "content/browser/notification_service_impl.h"

namespace content {
Expand Down Expand Up @@ -62,8 +63,8 @@ void NotificationRegistrar::Remove(NotificationObserver* observer,
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

Record record = { observer, type, source };
RecordVector::iterator found = std::find(
registered_.begin(), registered_.end(), record);
RecordVector::iterator found =
std::find(registered_.begin(), registered_.end(), record);
DCHECK(found != registered_.end());

registered_.erase(found);
Expand Down Expand Up @@ -109,8 +110,7 @@ bool NotificationRegistrar::IsRegistered(NotificationObserver* observer,
const NotificationSource& source) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Record record = { observer, type, source };
return std::find(registered_.begin(), registered_.end(), record) !=
registered_.end();
return base::ContainsValue(registered_, record);
}

} // namespace content
3 changes: 2 additions & 1 deletion content/renderer/media/webrtc/webrtc_audio_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
Expand Down Expand Up @@ -547,7 +548,7 @@ bool WebRtcAudioRenderer::AddPlayingState(
DCHECK(state->playing());
// Look up or add the |source| to the map.
PlayingStates& array = source_playing_states_[source];
if (std::find(array.begin(), array.end(), state) != array.end())
if (base::ContainsValue(array, state))
return false;

array.push_back(state);
Expand Down

0 comments on commit c8433ab

Please sign in to comment.