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:
parent
5086071294
commit
22970f573b
23 changed files with 83 additions and 87 deletions
|
@ -5,10 +5,10 @@
|
|||
#ifndef ELECTRON_SHELL_BROWSER_UI_ELECTRON_MENU_MODEL_H_
|
||||
#define ELECTRON_SHELL_BROWSER_UI_ELECTRON_MENU_MODEL_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<SharingItem> sharing_item_;
|
||||
#endif
|
||||
|
||||
std::map<int, std::u16string> toolTips_; // command id -> tooltip
|
||||
std::map<int, std::u16string> roles_; // command id -> role
|
||||
std::map<int, std::u16string> sublabels_; // command id -> sublabel
|
||||
base::flat_map<int, std::u16string> toolTips_; // command id -> tooltip
|
||||
base::flat_map<int, std::u16string> roles_; // command id -> role
|
||||
base::flat_map<int, std::u16string> sublabels_; // command id -> sublabel
|
||||
base::ObserverList<Observer> observers_;
|
||||
|
||||
base::WeakPtrFactory<ElectronMenuModel> weak_factory_{this};
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#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<ScopedGSignal>* signals) {
|
||||
std::map<int, GtkWidget*> radio_groups;
|
||||
base::flat_map<int, GtkWidget*> radio_groups;
|
||||
GtkWidget* menu_item = nullptr;
|
||||
for (size_t i = 0; i < model->GetItemCount(); ++i) {
|
||||
std::string label = ui::ConvertAcceleratorsFromWindowsStyle(
|
||||
|
|
|
@ -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<InspectableWebContents::NetworkResourceLoader>(
|
||||
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 {}
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
#ifndef ELECTRON_SHELL_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_H_
|
||||
#define ELECTRON_SHELL_BROWSER_UI_INSPECTABLE_WEB_CONTENTS_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#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<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator>
|
||||
base::flat_set<std::unique_ptr<NetworkResourceLoader>,
|
||||
base::UniquePtrComparator>
|
||||
loaders_;
|
||||
|
||||
using ExtensionsAPIs = std::map<std::string, std::string>;
|
||||
ExtensionsAPIs extensions_api_;
|
||||
// origin -> script
|
||||
base::flat_map<std::string, std::string> extensions_api_;
|
||||
|
||||
// Contains the set of synced settings.
|
||||
// The DevTools frontend *must* call `Register` for each setting prior to
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
|
||||
#include "shell/browser/ui/message_box.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
#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 {
|
||||
|
||||
// <ID, messageBox> map
|
||||
std::map<int, GtkWidget*>& GetDialogsMap() {
|
||||
static base::NoDestructor<std::map<int, GtkWidget*>> dialogs;
|
||||
base::flat_map<int, GtkWidget*>& GetDialogsMap() {
|
||||
static base::NoDestructor<base::flat_map<int, GtkWidget*>> dialogs;
|
||||
return *dialogs;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include "shell/browser/ui/message_box.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
@ -12,6 +11,7 @@
|
|||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#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 {
|
||||
|
||||
// <ID, messageBox> map
|
||||
std::map<int, NSAlert*>& GetDialogsMap() {
|
||||
static base::NoDestructor<std::map<int, NSAlert*>> dialogs;
|
||||
base::flat_map<int, NSAlert*>& GetDialogsMap() {
|
||||
static base::NoDestructor<base::flat_map<int, NSAlert*>> dialogs;
|
||||
return *dialogs;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#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<HMONITOR, int>;
|
||||
|
||||
// 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<HMONITOR, int> 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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue