From 17cb664e39d1811afd675db4ea533009523632de Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 6 Aug 2024 09:57:00 -0500 Subject: [PATCH] perf: don't build unused vectors in HidChooserContext (#43214) * refactor: remove unused code in HidChooserContext::DeviceRemoved() Co-authored-by: Charles Kerr * refactor: remove unused code in HidChooserContext::OnHidManagerConnectionError() Co-authored-by: Charles Kerr * refactor: use structured bindings for readability Co-authored-by: Charles Kerr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/browser/hid/hid_chooser_context.cc | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/shell/browser/hid/hid_chooser_context.cc b/shell/browser/hid/hid_chooser_context.cc index fa0d02562ab0..15540f2cfe3d 100644 --- a/shell/browser/hid/hid_chooser_context.cc +++ b/shell/browser/hid/hid_chooser_context.cc @@ -276,13 +276,8 @@ void HidChooserContext::DeviceRemoved(device::mojom::HidDeviceInfoPtr device) { if (CanStorePersistentEntry(*device)) return; - std::vector revoked_origins; - for (auto& map_entry : ephemeral_devices_) { - if (map_entry.second.erase(device->guid) > 0) - revoked_origins.push_back(map_entry.first); - } - if (revoked_origins.empty()) - return; + for (auto& [origin, guids] : ephemeral_devices_) + guids.erase(device->guid); } void HidChooserContext::DeviceChanged(device::mojom::HidDeviceInfoPtr device) { @@ -341,11 +336,6 @@ void HidChooserContext::OnHidManagerConnectionError() { hid_manager_.reset(); client_receiver_.reset(); devices_.clear(); - - std::vector revoked_origins; - revoked_origins.reserve(ephemeral_devices_.size()); - for (const auto& map_entry : ephemeral_devices_) - revoked_origins.push_back(map_entry.first); ephemeral_devices_.clear(); // Notify all device observers.