From cb7335b4f0173ef9c9e82d57254ce0c19eb4d1e0 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Thu, 27 Mar 2025 19:21:42 -0500 Subject: [PATCH] perf: avoid a triple-redundant map lookup in `ViewsDelegate::GetAppbarAutohideEdges()` (#46335) perf: avoid a triple-redundant map lookup in ViewsDelegate::GetAppbarAutohideEdges() Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/browser/ui/views/electron_views_delegate_win.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shell/browser/ui/views/electron_views_delegate_win.cc b/shell/browser/ui/views/electron_views_delegate_win.cc index cb67cccd7c5c..a6bce43396ee 100644 --- a/shell/browser/ui/views/electron_views_delegate_win.cc +++ b/shell/browser/ui/views/electron_views_delegate_win.cc @@ -119,8 +119,8 @@ 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_.contains(monitor)) - appbar_autohide_edge_map_[monitor] = EDGE_BOTTOM; + auto [iter, _] = appbar_autohide_edge_map_.try_emplace(monitor, EDGE_BOTTOM); + const int edges{iter->second}; // We use the SHAppBarMessage API to get the taskbar autohide state. This API // spins a modal loop which could cause callers to be reentered. To avoid @@ -133,9 +133,9 @@ int ViewsDelegate::GetAppbarAutohideEdges(HMONITOR monitor, base::BindOnce(&GetAppbarAutohideEdgesOnWorkerThread, monitor), base::BindOnce(&ViewsDelegate::OnGotAppbarAutohideEdges, weak_factory_.GetWeakPtr(), std::move(callback), monitor, - appbar_autohide_edge_map_[monitor])); + edges)); } - return appbar_autohide_edge_map_[monitor]; + return edges; } void ViewsDelegate::OnGotAppbarAutohideEdges(base::OnceClosure callback,