refactor: use std::map::try_emplace() over std::map::insert() (#46794)

refactor: prefer std::map::try_emplace() over std::map::insert()

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:
trop[bot] 2025-04-25 15:22:00 -05:00 committed by GitHub
parent 5dab95335b
commit d52670c749
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 15 additions and 21 deletions

View file

@ -85,7 +85,7 @@ void SerialChooserContext::GrantPortPermission(
const url::Origin& origin,
const device::mojom::SerialPortInfo& port,
content::RenderFrameHost* render_frame_host) {
port_info_.insert({port.token, port.Clone()});
port_info_.try_emplace(port.token, port.Clone());
if (CanStorePersistentEntry(port)) {
auto* permission_manager = static_cast<ElectronPermissionManager*>(
@ -270,7 +270,7 @@ void SerialChooserContext::SetUpPortManagerConnection(
void SerialChooserContext::OnGetDevices(
std::vector<device::mojom::SerialPortInfoPtr> ports) {
for (auto& port : ports)
port_info_.insert({port->token, std::move(port)});
port_info_.try_emplace(port->token, std::move(port));
is_initialized_ = true;
}