mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
refactor: use std::map::try_emplace() over std::map::insert() (#46761)
refactor: prefer std::map::try_emplace() over std::map::insert()
This commit is contained in:
@@ -116,8 +116,7 @@ SerialChooserController* ElectronSerialDelegate::AddControllerForFrame(
|
||||
render_frame_host, std::move(filters),
|
||||
std::move(allowed_bluetooth_service_class_ids), std::move(callback),
|
||||
web_contents, weak_factory_.GetWeakPtr());
|
||||
controller_map_.insert(
|
||||
std::make_pair(render_frame_host, std::move(controller)));
|
||||
controller_map_.try_emplace(render_frame_host, std::move(controller));
|
||||
return ControllerForFrame(render_frame_host);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,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*>(
|
||||
@@ -275,7 +275,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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user