refactor: use C++20's contains() method (#45742)
* chore: use std::map<>::contains() instead of count() or find() * chore: use std::map<>::contains() instead of base::Contains()
This commit is contained in:
parent
612da3ec47
commit
2a383e9ddd
29 changed files with 54 additions and 77 deletions
|
@ -9,7 +9,6 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
#include "content/public/common/color_parser.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
|
@ -1052,7 +1051,7 @@ void BaseWindow::UnhookWindowMessage(UINT message) {
|
|||
}
|
||||
|
||||
bool BaseWindow::IsWindowMessageHooked(UINT message) {
|
||||
return base::Contains(messages_callback_map_, message);
|
||||
return messages_callback_map_.contains(message);
|
||||
}
|
||||
|
||||
void BaseWindow::UnhookAllWindowMessages() {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/uuid.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
|
@ -58,7 +57,7 @@ GlobalShortcut::~GlobalShortcut() {
|
|||
}
|
||||
|
||||
void GlobalShortcut::OnKeyPressed(const ui::Accelerator& accelerator) {
|
||||
if (!base::Contains(accelerator_callback_map_, accelerator)) {
|
||||
if (!accelerator_callback_map_.contains(accelerator)) {
|
||||
// This should never occur, because if it does,
|
||||
// ui::GlobalAcceleratorListener notifies us with wrong accelerator.
|
||||
NOTREACHED();
|
||||
|
@ -68,7 +67,7 @@ void GlobalShortcut::OnKeyPressed(const ui::Accelerator& accelerator) {
|
|||
|
||||
void GlobalShortcut::ExecuteCommand(const extensions::ExtensionId& extension_id,
|
||||
const std::string& command_id) {
|
||||
if (!base::Contains(command_callback_map_, command_id)) {
|
||||
if (!command_callback_map_.contains(command_id)) {
|
||||
// This should never occur, because if it does, GlobalAcceleratorListener
|
||||
// notifies us with wrong command.
|
||||
NOTREACHED();
|
||||
|
@ -195,12 +194,12 @@ void GlobalShortcut::UnregisterSome(
|
|||
}
|
||||
|
||||
bool GlobalShortcut::IsRegistered(const ui::Accelerator& accelerator) {
|
||||
if (base::Contains(accelerator_callback_map_, accelerator)) {
|
||||
if (accelerator_callback_map_.contains(accelerator)) {
|
||||
return true;
|
||||
}
|
||||
const std::string command_str =
|
||||
extensions::Command::AcceleratorToString(accelerator);
|
||||
return base::Contains(command_callback_map_, command_str);
|
||||
return command_callback_map_.contains(command_str);
|
||||
}
|
||||
|
||||
void GlobalShortcut::UnregisterAll() {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/functional/callback_helpers.h"
|
||||
#include "content/public/browser/device_service.h"
|
||||
#include "gin/dictionary.h"
|
||||
|
@ -110,7 +109,7 @@ bool PowerSaveBlocker::Stop(int id) {
|
|||
}
|
||||
|
||||
bool PowerSaveBlocker::IsStarted(int id) const {
|
||||
return base::Contains(wake_lock_types_, id);
|
||||
return wake_lock_types_.contains(id);
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/containers/contains.h"
|
||||
#include "content/common/url_schemes.h"
|
||||
#include "content/public/browser/child_process_security_policy.h"
|
||||
#include "gin/handle.h"
|
||||
|
|
|
@ -1523,7 +1523,7 @@ v8::Local<v8::Promise> Session::ClearCodeCaches(
|
|||
if (options.Get("urls", &url_list) && !url_list.empty()) {
|
||||
url_matcher = base::BindRepeating(
|
||||
[](const std::set<GURL>& url_list, const GURL& url) {
|
||||
return base::Contains(url_list, url);
|
||||
return url_list.contains(url);
|
||||
},
|
||||
url_list);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include <vector>
|
||||
|
||||
#include "base/base64.h"
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/containers/fixed_flat_map.h"
|
||||
#include "base/containers/id_map.h"
|
||||
#include "base/files/file_util.h"
|
||||
|
@ -692,8 +691,7 @@ std::map<std::string, std::string> GetAddedFileSystemPaths(
|
|||
|
||||
bool IsDevToolsFileSystemAdded(content::WebContents* web_contents,
|
||||
const std::string& file_system_path) {
|
||||
return base::Contains(GetAddedFileSystemPaths(web_contents),
|
||||
file_system_path);
|
||||
return GetAddedFileSystemPaths(web_contents).contains(file_system_path);
|
||||
}
|
||||
|
||||
content::RenderFrameHost* GetRenderFrameHost(
|
||||
|
@ -4117,7 +4115,7 @@ void WebContents::DevToolsIndexPath(
|
|||
OnDevToolsIndexingDone(request_id, file_system_path);
|
||||
return;
|
||||
}
|
||||
if (devtools_indexing_jobs_.count(request_id) != 0)
|
||||
if (devtools_indexing_jobs_.contains(request_id))
|
||||
return;
|
||||
std::vector<std::string> excluded_folders;
|
||||
std::optional<base::Value> parsed_excluded_folders =
|
||||
|
|
|
@ -155,7 +155,7 @@ WebFrameMain::WebFrameMain(content::RenderFrameHost* rfh)
|
|||
if (!render_frame_detached_)
|
||||
GetFrameTreeNodeIdMap().emplace(frame_tree_node_id_, this);
|
||||
|
||||
DCHECK(GetFrameTokenMap().find(frame_token_) == GetFrameTokenMap().end());
|
||||
DCHECK(!GetFrameTokenMap().contains(frame_token_));
|
||||
GetFrameTokenMap().emplace(frame_token_, this);
|
||||
|
||||
// WebFrameMain should only be created for active or unloading frames.
|
||||
|
@ -193,7 +193,7 @@ void WebFrameMain::UpdateRenderFrameHost(content::RenderFrameHost* rfh) {
|
|||
// Ensure that RFH being swapped in doesn't already exist as its own
|
||||
// WebFrameMain instance.
|
||||
frame_token_ = rfh->GetGlobalFrameToken();
|
||||
DCHECK(GetFrameTokenMap().find(frame_token_) == GetFrameTokenMap().end());
|
||||
DCHECK(!GetFrameTokenMap().contains(frame_token_));
|
||||
GetFrameTokenMap().emplace(frame_token_, this);
|
||||
|
||||
render_frame_disposed_ = false;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/containers/fixed_flat_map.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/task/sequenced_task_runner.h"
|
||||
|
@ -251,7 +250,7 @@ bool WebRequest::RequestFilter::MatchesURL(
|
|||
|
||||
bool WebRequest::RequestFilter::MatchesType(
|
||||
extensions::WebRequestResourceType type) const {
|
||||
return types_.empty() || base::Contains(types_, type);
|
||||
return types_.empty() || types_.contains(type);
|
||||
}
|
||||
|
||||
bool WebRequest::RequestFilter::MatchesRequest(
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
#include "base/containers/contains.h"
|
||||
#include "base/containers/to_vector.h"
|
||||
#include "base/task/single_thread_task_runner.h"
|
||||
#include "gin/arguments.h"
|
||||
|
@ -233,7 +232,7 @@ std::vector<blink::MessagePortChannel> MessagePort::DisentanglePorts(
|
|||
// or cloned ports, throw an error (per section 8.3.3 of the HTML5 spec).
|
||||
for (unsigned i = 0; i < ports.size(); ++i) {
|
||||
auto* port = ports[i].get();
|
||||
if (!port || port->IsNeutered() || base::Contains(visited, port)) {
|
||||
if (!port || port->IsNeutered() || visited.contains(port)) {
|
||||
std::string type;
|
||||
if (!port)
|
||||
type = "null";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue