perf: avoid redundant map lookups in GlobalShortcut (34-x-y backport) (#46547)

perf: avoid redundant map lookups in `GlobalShortcut::OnKeyPressed()` (#46229)
This commit is contained in:
Charles Kerr
2025-04-07 15:28:23 -05:00
committed by GitHub
parent c413523434
commit 7672c78231

View File

@@ -6,6 +6,7 @@
#include <vector>
#include "base/containers/map_util.h"
#include "extensions/common/command.h"
#include "gin/dictionary.h"
#include "gin/handle.h"
@@ -52,12 +53,13 @@ GlobalShortcut::~GlobalShortcut() {
}
void GlobalShortcut::OnKeyPressed(const ui::Accelerator& accelerator) {
if (!accelerator_callback_map_.contains(accelerator)) {
// This should never occur, because if it does, GlobalShortcutListener
// notifies us with wrong accelerator.
if (auto* cb = base::FindOrNull(accelerator_callback_map_, accelerator)) {
cb->Run();
} else {
// This should never occur, because if it does,
// ui::GlobalAcceleratorListener notifies us with wrong accelerator.
NOTREACHED();
}
accelerator_callback_map_[accelerator].Run();
}
bool GlobalShortcut::RegisterAll(