From 22970f573b3ced41ad6b0e2c3e124e3a4ed6b40e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 5 Jan 2024 05:18:31 -0600 Subject: [PATCH] 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_ --- shell/browser/api/electron_api_app.h | 7 ++--- .../api/electron_api_desktop_capturer.cc | 15 +++++----- shell/browser/api/electron_api_menu_views.cc | 28 ++++++++++--------- shell/browser/api/electron_api_menu_views.h | 4 +-- .../api/electron_api_power_save_blocker.h | 6 ++-- .../electron_api_system_preferences_mac.mm | 4 +-- shell/browser/electron_browser_client.h | 8 +++--- .../browser/net/proxying_url_loader_factory.h | 6 ++-- .../linux/libnotify_notification.cc | 8 +++--- shell/browser/ui/electron_menu_model.h | 8 +++--- shell/browser/ui/gtk/menu_util.cc | 4 +-- shell/browser/ui/inspectable_web_contents.cc | 7 ++--- shell/browser/ui/inspectable_web_contents.h | 11 ++++---- shell/browser/ui/message_box_gtk.cc | 7 ++--- shell/browser/ui/message_box_mac.mm | 6 ++-- shell/browser/ui/message_box_win.cc | 10 +++---- .../ui/views/electron_views_delegate.h | 6 ++-- .../ui/views/electron_views_delegate_win.cc | 2 +- shell/browser/web_view_manager.h | 5 ++-- shell/common/api/electron_api_native_image.h | 6 ++-- shell/renderer/electron_renderer_client.h | 6 ++-- shell/renderer/web_worker_observer.cc | 2 +- shell/renderer/web_worker_observer.h | 4 +-- 23 files changed, 83 insertions(+), 87 deletions(-) diff --git a/shell/browser/api/electron_api_app.h b/shell/browser/api/electron_api_app.h index 035e34b589..082dc94152 100644 --- a/shell/browser/api/electron_api_app.h +++ b/shell/browser/api/electron_api_app.h @@ -5,11 +5,11 @@ #ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_APP_H_ #define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_APP_H_ -#include #include #include #include +#include "base/containers/flat_map.h" #include "base/task/cancelable_task_tracker.h" #include "chrome/browser/icon_manager.h" #include "chrome/browser/process_singleton.h" @@ -259,9 +259,8 @@ class App : public ElectronBrowserClient::Delegate, base::FilePath app_path_; - using ProcessMetricMap = - std::map>; - ProcessMetricMap app_metrics_; + // pid -> electron::ProcessMetric + base::flat_map> app_metrics_; bool disable_hw_acceleration_ = false; bool disable_domain_blocking_for_3DAPIs_ = false; diff --git a/shell/browser/api/electron_api_desktop_capturer.cc b/shell/browser/api/electron_api_desktop_capturer.cc index ab164c422e..87049e8544 100644 --- a/shell/browser/api/electron_api_desktop_capturer.cc +++ b/shell/browser/api/electron_api_desktop_capturer.cc @@ -4,11 +4,11 @@ #include "shell/browser/api/electron_api_desktop_capturer.h" -#include #include #include #include +#include "base/containers/flat_map.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_restrictions.h" @@ -42,11 +42,11 @@ #if BUILDFLAG(IS_LINUX) // Private function in ui/base/x/x11_display_util.cc -std::map GetMonitors( +base::flat_map GetMonitors( std::pair version, x11::RandR* randr, x11::Window window) { - std::map output_to_monitor; + base::flat_map output_to_monitor; if (version >= std::pair{1, 5}) { if (auto reply = randr->GetMonitors({window}).Sync()) { for (size_t monitor = 0; monitor < reply->monitors.size(); monitor++) { @@ -76,12 +76,12 @@ std::vector GetEDIDProperty(x11::RandR* randr, // Find the mapping from monitor name atom to the display identifier // that the screen API uses. Based on the logic in BuildDisplaysFromXRandRInfo // in ui/base/x/x11_display_util.cc -std::map MonitorAtomIdToDisplayId() { +base::flat_map MonitorAtomIdToDisplayId() { auto* connection = x11::Connection::Get(); auto& randr = connection->randr(); auto x_root_window = ui::GetX11RootWindow(); - std::map monitor_atom_to_display; + base::flat_map monitor_atom_to_display; auto resources = randr.GetScreenResourcesCurrent({x_root_window}).Sync(); if (!resources) { @@ -89,7 +89,7 @@ std::map MonitorAtomIdToDisplayId() { return monitor_atom_to_display; } - std::map output_to_monitor = + const auto output_to_monitor = GetMonitors(connection->randr_version(), &randr, x_root_window); auto monitors_reply = randr.GetMonitors({x_root_window}).Sync(); @@ -385,8 +385,7 @@ void DesktopCapturer::UpdateSourcesList(DesktopMediaList* list) { // display name atom and the display id is either the EDID or the // loop index when that display was found (see // BuildDisplaysFromXRandRInfo in ui/base/x/x11_display_util.cc) - std::map monitor_atom_to_display_id = - MonitorAtomIdToDisplayId(); + const auto monitor_atom_to_display_id = MonitorAtomIdToDisplayId(); for (auto& source : screen_sources) { auto display_id_iter = monitor_atom_to_display_id.find(source.media_list_source.id.id); diff --git a/shell/browser/api/electron_api_menu_views.cc b/shell/browser/api/electron_api_menu_views.cc index 8a696ec5c0..c83c2215d4 100644 --- a/shell/browser/api/electron_api_menu_views.cc +++ b/shell/browser/api/electron_api_menu_views.cc @@ -52,24 +52,26 @@ void MenuViews::PopupAt(BaseWindow* window, auto close_callback = base::AdaptCallbackForRepeating( base::BindOnce(&MenuViews::OnClosed, weak_factory_.GetWeakPtr(), window_id, std::move(callback_with_ref))); - menu_runners_[window_id] = + auto& runner = menu_runners_[window_id] = std::make_unique(model(), flags, std::move(close_callback)); - menu_runners_[window_id]->RunMenuAt( - native_window->widget(), nullptr, gfx::Rect(location, gfx::Size()), - views::MenuAnchorPosition::kTopLeft, source_type); + runner->RunMenuAt(native_window->widget(), nullptr, + gfx::Rect{location, gfx::Size{}}, + views::MenuAnchorPosition::kTopLeft, source_type); } void MenuViews::ClosePopupAt(int32_t window_id) { - auto runner = menu_runners_.find(window_id); - if (runner != menu_runners_.end()) { + if (auto iter = menu_runners_.find(window_id); iter != menu_runners_.end()) { // Close the runner for the window. - runner->second->Cancel(); - } else if (window_id == -1) { - // Or just close all opened runners. - for (auto it = menu_runners_.begin(); it != menu_runners_.end();) { - // The iterator is invalidated after the call. - (it++)->second->Cancel(); - } + iter->second->Cancel(); + return; + } + + if (window_id == -1) { + // When -1 is passed in, close all opened runners. + // Note: `Cancel()` invalidaes iters, so move() to a temp before looping + auto tmp = std::move(menu_runners_); + for (auto& [id, runner] : tmp) + runner->Cancel(); } } diff --git a/shell/browser/api/electron_api_menu_views.h b/shell/browser/api/electron_api_menu_views.h index 39b7e01662..c4b27d89d4 100644 --- a/shell/browser/api/electron_api_menu_views.h +++ b/shell/browser/api/electron_api_menu_views.h @@ -5,9 +5,9 @@ #ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_MENU_VIEWS_H_ #define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_MENU_VIEWS_H_ -#include #include +#include "base/containers/flat_map.h" #include "base/memory/weak_ptr.h" #include "shell/browser/api/electron_api_menu.h" #include "ui/display/screen.h" @@ -33,7 +33,7 @@ class MenuViews : public Menu { void OnClosed(int32_t window_id, base::OnceClosure callback); // window ID -> open context menu - std::map> menu_runners_; + base::flat_map> menu_runners_; base::WeakPtrFactory weak_factory_{this}; }; diff --git a/shell/browser/api/electron_api_power_save_blocker.h b/shell/browser/api/electron_api_power_save_blocker.h index ad60bfbd83..e4e495dbc2 100644 --- a/shell/browser/api/electron_api_power_save_blocker.h +++ b/shell/browser/api/electron_api_power_save_blocker.h @@ -5,8 +5,7 @@ #ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_POWER_SAVE_BLOCKER_H_ #define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_POWER_SAVE_BLOCKER_H_ -#include - +#include "base/containers/flat_map.h" #include "gin/handle.h" #include "gin/object_template_builder.h" #include "gin/wrappable.h" @@ -48,8 +47,7 @@ class PowerSaveBlocker : public gin::Wrappable { bool is_wake_lock_active_ = false; // Map from id to the corresponding blocker type for each request. - using WakeLockTypeMap = std::map; - WakeLockTypeMap wake_lock_types_; + base::flat_map wake_lock_types_; mojo::Remote wake_lock_; }; diff --git a/shell/browser/api/electron_api_system_preferences_mac.mm b/shell/browser/api/electron_api_system_preferences_mac.mm index 7271f47fb7..c57aa1ea13 100644 --- a/shell/browser/api/electron_api_system_preferences_mac.mm +++ b/shell/browser/api/electron_api_system_preferences_mac.mm @@ -4,7 +4,6 @@ #include "shell/browser/api/electron_api_system_preferences.h" -#include #include #include @@ -14,6 +13,7 @@ #import #include "base/apple/scoped_cftyperef.h" +#include "base/containers/flat_map.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" #include "base/task/sequenced_task_runner.h" @@ -81,7 +81,7 @@ namespace { int g_next_id = 0; // The map to convert |id| to |int|. -std::map g_id_map; +base::flat_map g_id_map; AVMediaType ParseMediaType(const std::string& media_type) { if (media_type == "camera") { diff --git a/shell/browser/electron_browser_client.h b/shell/browser/electron_browser_client.h index 3f8b1c63ce..80131015f3 100644 --- a/shell/browser/electron_browser_client.h +++ b/shell/browser/electron_browser_client.h @@ -5,12 +5,12 @@ #ifndef ELECTRON_SHELL_BROWSER_ELECTRON_BROWSER_CLIENT_H_ #define ELECTRON_SHELL_BROWSER_ELECTRON_BROWSER_CLIENT_H_ -#include #include -#include #include #include +#include "base/containers/flat_map.h" +#include "base/containers/flat_set.h" #include "base/files/file_path.h" #include "base/memory/raw_ptr.h" #include "base/synchronization/lock.h" @@ -313,9 +313,9 @@ class ElectronBrowserClient : public content::ContentBrowserClient, bool IsRendererSubFrame(int process_id) const; // pending_render_process => web contents. - std::map pending_processes_; + base::flat_map pending_processes_; - std::set renderer_is_subframe_; + base::flat_set renderer_is_subframe_; std::unique_ptr notification_service_; std::unique_ptr notification_presenter_; diff --git a/shell/browser/net/proxying_url_loader_factory.h b/shell/browser/net/proxying_url_loader_factory.h index 2e894e0107..49a107e5d5 100644 --- a/shell/browser/net/proxying_url_loader_factory.h +++ b/shell/browser/net/proxying_url_loader_factory.h @@ -6,12 +6,12 @@ #define ELECTRON_SHELL_BROWSER_NET_PROXYING_URL_LOADER_FACTORY_H_ #include -#include #include #include #include #include +#include "base/containers/flat_map.h" #include "base/memory/raw_ptr.h" #include "base/memory/raw_ref.h" #include "base/memory/weak_ptr.h" @@ -274,11 +274,11 @@ class ProxyingURLLoaderFactory // Mapping from our own internally generated request ID to an // InProgressRequest instance. - std::map> requests_; + base::flat_map> requests_; // A mapping from the network stack's notion of request ID to our own // internally generated request ID for the same request. - std::map network_request_id_to_web_request_id_; + base::flat_map network_request_id_to_web_request_id_; std::vector ignore_connections_limit_domains_; }; diff --git a/shell/browser/notifications/linux/libnotify_notification.cc b/shell/browser/notifications/linux/libnotify_notification.cc index 0dcfad8aa6..e039b382e3 100644 --- a/shell/browser/notifications/linux/libnotify_notification.cc +++ b/shell/browser/notifications/linux/libnotify_notification.cc @@ -4,9 +4,9 @@ #include "shell/browser/notifications/linux/libnotify_notification.h" -#include #include +#include "base/containers/flat_set.h" #include "base/files/file_enumerator.h" #include "base/functional/bind.h" #include "base/logging.h" @@ -24,8 +24,8 @@ namespace { LibNotifyLoader libnotify_loader_; -const std::set& GetServerCapabilities() { - static std::set caps; +const base::flat_set& GetServerCapabilities() { + static base::flat_set caps; if (caps.empty()) { auto* capabilities = libnotify_loader_.notify_get_server_caps(); for (auto* l = capabilities; l != nullptr; l = l->next) @@ -36,7 +36,7 @@ const std::set& GetServerCapabilities() { } bool HasCapability(const std::string& capability) { - return GetServerCapabilities().count(capability) != 0; + return GetServerCapabilities().contains(capability); } bool NotifierSupportsActions() { diff --git a/shell/browser/ui/electron_menu_model.h b/shell/browser/ui/electron_menu_model.h index 2f13f1ad4b..ba96b14187 100644 --- a/shell/browser/ui/electron_menu_model.h +++ b/shell/browser/ui/electron_menu_model.h @@ -5,10 +5,10 @@ #ifndef ELECTRON_SHELL_BROWSER_UI_ELECTRON_MENU_MODEL_H_ #define ELECTRON_SHELL_BROWSER_UI_ELECTRON_MENU_MODEL_H_ -#include #include #include +#include "base/containers/flat_map.h" #include "base/files/file_path.h" #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" @@ -119,9 +119,9 @@ class ElectronMenuModel : public ui::SimpleMenuModel { absl::optional sharing_item_; #endif - std::map toolTips_; // command id -> tooltip - std::map roles_; // command id -> role - std::map sublabels_; // command id -> sublabel + base::flat_map toolTips_; // command id -> tooltip + base::flat_map roles_; // command id -> role + base::flat_map sublabels_; // command id -> sublabel base::ObserverList observers_; base::WeakPtrFactory weak_factory_{this}; diff --git a/shell/browser/ui/gtk/menu_util.cc b/shell/browser/ui/gtk/menu_util.cc index e95d1799a0..8eb5810009 100644 --- a/shell/browser/ui/gtk/menu_util.cc +++ b/shell/browser/ui/gtk/menu_util.cc @@ -7,9 +7,9 @@ #include #include -#include #include +#include "base/containers/flat_map.h" #include "base/strings/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "shell/browser/ui/gtk_util.h" @@ -150,7 +150,7 @@ void BuildSubmenuFromModel(ui::MenuModel* model, MenuActivatedCallback item_activated_cb, bool* block_activation, std::vector* signals) { - std::map radio_groups; + base::flat_map radio_groups; GtkWidget* menu_item = nullptr; for (size_t i = 0; i < model->GetItemCount(); ++i) { std::string label = ui::ConvertAcceleratorsFromWindowsStyle( diff --git a/shell/browser/ui/inspectable_web_contents.cc b/shell/browser/ui/inspectable_web_contents.cc index b44ebf44d0..c05601ce9d 100644 --- a/shell/browser/ui/inspectable_web_contents.cc +++ b/shell/browser/ui/inspectable_web_contents.cc @@ -203,11 +203,10 @@ class InspectableWebContents::NetworkResourceLoader URLLoaderFactoryHolder url_loader_factory, DispatchCallback callback, base::TimeDelta retry_delay = base::TimeDelta()) { - auto resource_loader = + bindings->loaders_.insert( std::make_unique( stream_id, bindings, resource_request, traffic_annotation, - std::move(url_loader_factory), std::move(callback), retry_delay); - bindings->loaders_.insert(std::move(resource_loader)); + std::move(url_loader_factory), std::move(callback), retry_delay)); } NetworkResourceLoader( @@ -308,7 +307,7 @@ class InspectableWebContents::NetworkResourceLoader std::move(callback_).Run(&response); } - bindings_->loaders_.erase(bindings_->loaders_.find(this)); + bindings_->loaders_.erase(this); } void OnRetry(base::OnceClosure start_retry) override {} diff --git a/shell/browser/ui/inspectable_web_contents.h b/shell/browser/ui/inspectable_web_contents.h index 80e9389364..1bbd2bde79 100644 --- a/shell/browser/ui/inspectable_web_contents.h +++ b/shell/browser/ui/inspectable_web_contents.h @@ -6,11 +6,11 @@ #ifndef ELECTRON_SHELL_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_H_ #define ELECTRON_SHELL_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_H_ -#include #include -#include #include +#include "base/containers/flat_map.h" +#include "base/containers/flat_set.h" #include "base/containers/span.h" #include "base/containers/unique_ptr_adapters.h" #include "base/memory/raw_ptr.h" @@ -241,11 +241,12 @@ class InspectableWebContents embedder_message_dispatcher_; class NetworkResourceLoader; - std::set, base::UniquePtrComparator> + base::flat_set, + base::UniquePtrComparator> loaders_; - using ExtensionsAPIs = std::map; - ExtensionsAPIs extensions_api_; + // origin -> script + base::flat_map extensions_api_; // Contains the set of synced settings. // The DevTools frontend *must* call `Register` for each setting prior to diff --git a/shell/browser/ui/message_box_gtk.cc b/shell/browser/ui/message_box_gtk.cc index 5b35b65c48..dd5130722c 100644 --- a/shell/browser/ui/message_box_gtk.cc +++ b/shell/browser/ui/message_box_gtk.cc @@ -4,9 +4,8 @@ #include "shell/browser/ui/message_box.h" -#include - #include "base/containers/contains.h" +#include "base/containers/flat_map.h" #include "base/functional/bind.h" #include "base/functional/callback.h" #include "base/memory/raw_ptr.h" @@ -43,8 +42,8 @@ MessageBoxSettings::~MessageBoxSettings() = default; namespace { // map -std::map& GetDialogsMap() { - static base::NoDestructor> dialogs; +base::flat_map& GetDialogsMap() { + static base::NoDestructor> dialogs; return *dialogs; } diff --git a/shell/browser/ui/message_box_mac.mm b/shell/browser/ui/message_box_mac.mm index 710e7716d1..63d93d3efe 100644 --- a/shell/browser/ui/message_box_mac.mm +++ b/shell/browser/ui/message_box_mac.mm @@ -4,7 +4,6 @@ #include "shell/browser/ui/message_box.h" -#include #include #include #include @@ -12,6 +11,7 @@ #import #include "base/containers/contains.h" +#include "base/containers/flat_map.h" #include "base/functional/callback.h" #include "base/mac/mac_util.h" #include "base/no_destructor.h" @@ -31,8 +31,8 @@ MessageBoxSettings::~MessageBoxSettings() = default; namespace { // map -std::map& GetDialogsMap() { - static base::NoDestructor> dialogs; +base::flat_map& GetDialogsMap() { + static base::NoDestructor> dialogs; return *dialogs; } diff --git a/shell/browser/ui/message_box_win.cc b/shell/browser/ui/message_box_win.cc index 4082a76dc2..f5f64dae50 100644 --- a/shell/browser/ui/message_box_win.cc +++ b/shell/browser/ui/message_box_win.cc @@ -8,10 +8,10 @@ #include -#include #include #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>& GetDialogsMap() { - static base::NoDestructor>> dialogs; +base::flat_map>& GetDialogsMap() { + static base::NoDestructor>> 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& buttons, - std::map* id_map, + base::flat_map* id_map, TASKDIALOG_COMMON_BUTTON_FLAGS* button_flags, std::vector* 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 id_map; + base::flat_map id_map; std::vector dialog_buttons; if (no_link) { for (size_t i = 0; i < buttons.size(); ++i) diff --git a/shell/browser/ui/views/electron_views_delegate.h b/shell/browser/ui/views/electron_views_delegate.h index 3f261c77d4..ac8cb219dc 100644 --- a/shell/browser/ui/views/electron_views_delegate.h +++ b/shell/browser/ui/views/electron_views_delegate.h @@ -5,11 +5,11 @@ #ifndef ELECTRON_SHELL_BROWSER_UI_VIEWS_ELECTRON_VIEWS_DELEGATE_H_ #define ELECTRON_SHELL_BROWSER_UI_VIEWS_ELECTRON_VIEWS_DELEGATE_H_ -#include #include #include #include "base/compiler_specific.h" +#include "base/containers/flat_map.h" #include "ui/views/views_delegate.h" namespace electron { @@ -58,8 +58,6 @@ class ViewsDelegate : public views::ViewsDelegate { private: #if BUILDFLAG(IS_WIN) - using AppbarAutohideEdgeMap = std::map; - // Callback on main thread with the edges. |returned_edges| is the value that // was returned from the call to GetAutohideEdges() that initiated the lookup. void OnGotAppbarAutohideEdges(base::OnceClosure callback, @@ -67,7 +65,7 @@ class ViewsDelegate : public views::ViewsDelegate { int returned_edges, int edges); - AppbarAutohideEdgeMap appbar_autohide_edge_map_; + base::flat_map appbar_autohide_edge_map_; // If true we're in the process of notifying a callback from // GetAutohideEdges().start a new query. bool in_autohide_edges_callback_ = false; diff --git a/shell/browser/ui/views/electron_views_delegate_win.cc b/shell/browser/ui/views/electron_views_delegate_win.cc index 6c8048e70a..cb67cccd7c 100644 --- a/shell/browser/ui/views/electron_views_delegate_win.cc +++ b/shell/browser/ui/views/electron_views_delegate_win.cc @@ -119,7 +119,7 @@ int ViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor, // in us thinking there is no auto-hide edges. By returning at least one edge // we don't initially go fullscreen until we figure out the real auto-hide // edges. - if (!appbar_autohide_edge_map_.count(monitor)) + if (!appbar_autohide_edge_map_.contains(monitor)) appbar_autohide_edge_map_[monitor] = EDGE_BOTTOM; // We use the SHAppBarMessage API to get the taskbar autohide state. This API diff --git a/shell/browser/web_view_manager.h b/shell/browser/web_view_manager.h index 1e40cd26c7..e533f21acf 100644 --- a/shell/browser/web_view_manager.h +++ b/shell/browser/web_view_manager.h @@ -5,8 +5,7 @@ #ifndef ELECTRON_SHELL_BROWSER_WEB_VIEW_MANAGER_H_ #define ELECTRON_SHELL_BROWSER_WEB_VIEW_MANAGER_H_ -#include - +#include "base/containers/flat_map.h" #include "base/memory/raw_ptr.h" #include "content/public/browser/browser_plugin_guest_manager.h" @@ -38,7 +37,7 @@ class WebViewManager : public content::BrowserPluginGuestManager { raw_ptr embedder; }; // guest_instance_id => (web_contents, embedder) - std::map web_contents_embedder_map_; + base::flat_map web_contents_embedder_map_; }; } // namespace electron diff --git a/shell/common/api/electron_api_native_image.h b/shell/common/api/electron_api_native_image.h index af646e4d85..1a346444d1 100644 --- a/shell/common/api/electron_api_native_image.h +++ b/shell/common/api/electron_api_native_image.h @@ -5,10 +5,10 @@ #ifndef ELECTRON_SHELL_COMMON_API_ELECTRON_API_NATIVE_IMAGE_H_ #define ELECTRON_SHELL_COMMON_API_ELECTRON_API_NATIVE_IMAGE_H_ -#include #include #include +#include "base/containers/flat_map.h" #include "base/memory/raw_ptr.h" #include "base/values.h" #include "gin/handle.h" @@ -130,7 +130,9 @@ class NativeImage : public gin::Wrappable { #if BUILDFLAG(IS_WIN) base::FilePath hicon_path_; - std::map hicons_; + + // size -> hicon + base::flat_map hicons_; #endif gfx::Image image_; diff --git a/shell/renderer/electron_renderer_client.h b/shell/renderer/electron_renderer_client.h index d577e1a3da..0251fcb7a4 100644 --- a/shell/renderer/electron_renderer_client.h +++ b/shell/renderer/electron_renderer_client.h @@ -6,8 +6,8 @@ #define ELECTRON_SHELL_RENDERER_ELECTRON_RENDERER_CLIENT_H_ #include -#include +#include "base/containers/flat_set.h" #include "shell/renderer/renderer_client_base.h" namespace node { @@ -57,12 +57,12 @@ class ElectronRendererClient : public RendererClientBase { // The node::Environment::GetCurrent API does not return nullptr when it // is called for a context without node::Environment, so we have to keep // a book of the environments created. - std::set> environments_; + base::flat_set> environments_; // Getting main script context from web frame would lazily initializes // its script context. Doing so in a web page without scripts would trigger // assertion, so we have to keep a book of injected web frames. - std::set injected_frames_; + base::flat_set injected_frames_; }; } // namespace electron diff --git a/shell/renderer/web_worker_observer.cc b/shell/renderer/web_worker_observer.cc index 1763d360ad..6adb042bb7 100644 --- a/shell/renderer/web_worker_observer.cc +++ b/shell/renderer/web_worker_observer.cc @@ -98,7 +98,7 @@ void WebWorkerObserver::ContextWillDestroy(v8::Local context) { DCHECK_EQ(microtask_queue->GetMicrotasksScopeDepth(), 0); microtask_queue->set_microtasks_policy(v8::MicrotasksPolicy::kExplicit); - std::erase_if(environments_, + base::EraseIf(environments_, [env](auto const& item) { return item.get() == env; }); microtask_queue->set_microtasks_policy(old_policy); diff --git a/shell/renderer/web_worker_observer.h b/shell/renderer/web_worker_observer.h index 897052a3c6..7c47283005 100644 --- a/shell/renderer/web_worker_observer.h +++ b/shell/renderer/web_worker_observer.h @@ -6,8 +6,8 @@ #define ELECTRON_SHELL_RENDERER_WEB_WORKER_OBSERVER_H_ #include -#include +#include "base/containers/flat_set.h" #include "v8/include/v8.h" namespace node { @@ -42,7 +42,7 @@ class WebWorkerObserver { private: std::unique_ptr node_bindings_; std::unique_ptr electron_bindings_; - std::set> environments_; + base::flat_set> environments_; }; } // namespace electron