perf: use flat_set, flat_map for small, trivially-moved containers (#40817)

* refactor: use base::flat_map in ElectronMenuModel

* refactor: use base::flat_map in BuildSubmenuFromModel()

* refactor: use base::flat_map in GetDialogsMap()

* refactor: use base::flat_map in DesktopCapturer

* refactor: use base::flat_map, flat_set in ElectronBrowserClient

* refactor: use base::flat_map in ProxyingURLLoaderFactory

* refactor: use base::flat_map in MapToCommonId()

* refactor: use base::flat_map for g_map_id

* refactor: use base::flat_map for ViewsDelegate::AppbarAutohideEdgeMap

* refactor: use base::flat_map for App::app_metrics_

* refactor: use base::flat_map for PowerSaveBlocker::wake_lock_types_

* refactor: use base::flat_map for NativeImage::hicons_

* refactor: use base::flat_map for MenuViews::menu_runners_

* refactor: use base::flat_map for WebViewManager::web_contents_embedder_map_

* refactor: use base::flat_map for InspectableWebContents::extensions_api_

* refactor: use base::flat_set for libnotify GetServerCapabilities()

* refactor: use base::flat_set for InspectableWebContents::loaders_

* refactor: use base::flat_set for ElectronRendererClient::environments_

refactor: use base::flat_set for ElectronRendererClient::injected_frames_

* refactor: use base::flat_set for WebWorkerObserver::environments_
This commit is contained in:
Charles Kerr 2024-01-05 05:18:31 -06:00 committed by GitHub
parent 5086071294
commit 22970f573b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 83 additions and 87 deletions

View file

@ -8,10 +8,10 @@
#include <commctrl.h>
#include <map>
#include <vector>
#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/no_destructor.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@ -41,8 +41,8 @@ struct DialogResult {
// Note that the HWND is stored in a unique_ptr, because the pointer of HWND
// will be passed between threads and we need to ensure the memory of HWND is
// not changed while dialogs map is modified.
std::map<int, std::unique_ptr<HWND>>& GetDialogsMap() {
static base::NoDestructor<std::map<int, std::unique_ptr<HWND>>> dialogs;
base::flat_map<int, std::unique_ptr<HWND>>& GetDialogsMap() {
static base::NoDestructor<base::flat_map<int, std::unique_ptr<HWND>>> dialogs;
return *dialogs;
}
@ -95,7 +95,7 @@ CommonButtonID GetCommonID(const std::wstring& button) {
// Determine whether the buttons are common buttons, if so map common ID
// to button ID.
void MapToCommonID(const std::vector<std::wstring>& buttons,
std::map<int, int>* id_map,
base::flat_map<int, int>* id_map,
TASKDIALOG_COMMON_BUTTON_FLAGS* button_flags,
std::vector<TASKDIALOG_BUTTON>* dialog_buttons) {
for (size_t i = 0; i < buttons.size(); ++i) {
@ -215,7 +215,7 @@ DialogResult ShowTaskDialogWstr(gfx::AcceleratedWidget parent,
// Iterate through the buttons, put common buttons in dwCommonButtons
// and custom buttons in pButtons.
std::map<int, int> id_map;
base::flat_map<int, int> id_map;
std::vector<TASKDIALOG_BUTTON> dialog_buttons;
if (no_link) {
for (size_t i = 0; i < buttons.size(); ++i)