perf: avoid redundant map lookups in GlobalShortcut
(#46262)
* perf: avoid redundant map lookup in GlobalShortcut::OnKeyPressed() Co-authored-by: Charles Kerr <charles@charleskerr.com> * perf: avoid redundant map lookup in GlobalShortcut::ExecuteCommand() Co-authored-by: Charles Kerr <charles@charleskerr.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
parent
7d27b2c542
commit
d38c2d507e
1 changed files with 7 additions and 4 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/map_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "base/uuid.h"
|
||||
#include "components/prefs/pref_service.h"
|
||||
|
@ -57,22 +58,24 @@ GlobalShortcut::~GlobalShortcut() {
|
|||
}
|
||||
|
||||
void GlobalShortcut::OnKeyPressed(const ui::Accelerator& accelerator) {
|
||||
if (!accelerator_callback_map_.contains(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();
|
||||
}
|
||||
|
||||
void GlobalShortcut::ExecuteCommand(const extensions::ExtensionId& extension_id,
|
||||
const std::string& command_id) {
|
||||
if (!command_callback_map_.contains(command_id)) {
|
||||
if (auto* cb = base::FindOrNull(command_callback_map_, command_id)) {
|
||||
cb->Run();
|
||||
} else {
|
||||
// This should never occur, because if it does, GlobalAcceleratorListener
|
||||
// notifies us with wrong command.
|
||||
NOTREACHED();
|
||||
}
|
||||
command_callback_map_[command_id].Run();
|
||||
}
|
||||
|
||||
bool GlobalShortcut::RegisterAll(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue