perf: don't build unused vectors in HidChooserContext (#43192)

* refactor: remove unused code in HidChooserContext::DeviceRemoved()

* refactor: remove unused code in HidChooserContext::OnHidManagerConnectionError()

* refactor: use structured bindings for readability
This commit is contained in:
Charles Kerr 2024-08-05 08:31:58 -05:00 committed by GitHub
parent 6877671390
commit 3d766e9ccb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -273,13 +273,8 @@ void HidChooserContext::DeviceRemoved(device::mojom::HidDeviceInfoPtr device) {
if (CanStorePersistentEntry(*device))
return;
std::vector<url::Origin> 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) {
@ -338,11 +333,6 @@ void HidChooserContext::OnHidManagerConnectionError() {
hid_manager_.reset();
client_receiver_.reset();
devices_.clear();
std::vector<url::Origin> 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.