mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Use map.emplace() instead of map.insert(std::pair).
This avoids a copy of the pair into the map.
This commit is contained in:
parent
57d7359b1a
commit
ed2db80990
|
@ -71,8 +71,7 @@ static int32_t GetAmount(CargoMonitorMap &monitor_map, CargoMonitorID monitor, b
|
||||||
CargoMonitorMap::iterator iter = monitor_map.find(monitor);
|
CargoMonitorMap::iterator iter = monitor_map.find(monitor);
|
||||||
if (iter == monitor_map.end()) {
|
if (iter == monitor_map.end()) {
|
||||||
if (keep_monitoring) {
|
if (keep_monitoring) {
|
||||||
std::pair<CargoMonitorID, uint32_t> p(monitor, 0);
|
monitor_map.emplace(monitor, 0);
|
||||||
monitor_map.insert(p);
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -99,7 +99,7 @@ void BuildCargoLabelMap()
|
||||||
/* Label already exists, don't addd again. */
|
/* Label already exists, don't addd again. */
|
||||||
if (CargoSpec::label_map.count(cs.label) != 0) continue;
|
if (CargoSpec::label_map.count(cs.label) != 0) continue;
|
||||||
|
|
||||||
CargoSpec::label_map.insert(std::make_pair(cs.label, cs.Index()));
|
CargoSpec::label_map.emplace(cs.label, cs.Index());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ bool ClientNetworkContentSocketHandler::Receive_SERVER_INFO(Packet &p)
|
||||||
for (uint i = 0; i < dependency_count; i++) {
|
for (uint i = 0; i < dependency_count; i++) {
|
||||||
ContentID dependency_cid = (ContentID)p.Recv_uint32();
|
ContentID dependency_cid = (ContentID)p.Recv_uint32();
|
||||||
ci->dependencies.push_back(dependency_cid);
|
ci->dependencies.push_back(dependency_cid);
|
||||||
this->reverse_dependency_map.insert({ dependency_cid, ci->id });
|
this->reverse_dependency_map.emplace(dependency_cid, ci->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint tag_count = p.Recv_uint8();
|
uint tag_count = p.Recv_uint8();
|
||||||
|
|
|
@ -591,8 +591,7 @@ typedef std::map<uint32_t, const GRFConfig *> GrfIdMap; ///< Map of grfid to the
|
||||||
static void FillGrfidMap(const GRFConfig *c, GrfIdMap *grfid_map)
|
static void FillGrfidMap(const GRFConfig *c, GrfIdMap *grfid_map)
|
||||||
{
|
{
|
||||||
while (c != nullptr) {
|
while (c != nullptr) {
|
||||||
std::pair<uint32_t, const GRFConfig *> p(c->ident.grfid, c);
|
grfid_map->emplace(c->ident.grfid, c);
|
||||||
grfid_map->insert(p);
|
|
||||||
c = c->next;
|
c = c->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,7 @@ struct CMDLChunkHandler : ChunkHandler {
|
||||||
|
|
||||||
if (fix) storage.number = FixupCargoMonitor(storage.number);
|
if (fix) storage.number = FixupCargoMonitor(storage.number);
|
||||||
|
|
||||||
std::pair<CargoMonitorID, uint32_t> p(storage.number, storage.amount);
|
_cargo_deliveries.emplace(storage.number, storage.amount);
|
||||||
_cargo_deliveries.insert(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -125,8 +124,7 @@ struct CMPUChunkHandler : ChunkHandler {
|
||||||
|
|
||||||
if (fix) storage.number = FixupCargoMonitor(storage.number);
|
if (fix) storage.number = FixupCargoMonitor(storage.number);
|
||||||
|
|
||||||
std::pair<CargoMonitorID, uint32_t> p(storage.number, storage.amount);
|
_cargo_pickups.emplace(storage.number, storage.amount);
|
||||||
_cargo_pickups.insert(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -318,7 +318,7 @@ public:
|
||||||
for (uint32_t j = 0; j < num_flows; ++j) {
|
for (uint32_t j = 0; j < num_flows; ++j) {
|
||||||
SlObject(&flow, this->GetLoadDescription());
|
SlObject(&flow, this->GetLoadDescription());
|
||||||
if (fs == nullptr || prev_source != flow.source) {
|
if (fs == nullptr || prev_source != flow.source) {
|
||||||
fs = &(ge->flows.insert(std::make_pair(flow.source, FlowStat(flow.via, flow.share, flow.restricted))).first->second);
|
fs = &(ge->flows.emplace(flow.source, FlowStat(flow.via, flow.share, flow.restricted))).first->second;
|
||||||
} else {
|
} else {
|
||||||
fs->AppendShare(flow.via, flow.share, flow.restricted);
|
fs->AppendShare(flow.via, flow.share, flow.restricted);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4810,7 +4810,7 @@ void FlowStatMap::AddFlow(StationID origin, StationID via, uint flow)
|
||||||
{
|
{
|
||||||
FlowStatMap::iterator origin_it = this->find(origin);
|
FlowStatMap::iterator origin_it = this->find(origin);
|
||||||
if (origin_it == this->end()) {
|
if (origin_it == this->end()) {
|
||||||
this->insert(std::make_pair(origin, FlowStat(via, flow)));
|
this->emplace(origin, FlowStat(via, flow));
|
||||||
} else {
|
} else {
|
||||||
origin_it->second.ChangeShare(via, flow);
|
origin_it->second.ChangeShare(via, flow);
|
||||||
assert(!origin_it->second.GetShares()->empty());
|
assert(!origin_it->second.GetShares()->empty());
|
||||||
|
@ -4831,7 +4831,7 @@ void FlowStatMap::PassOnFlow(StationID origin, StationID via, uint flow)
|
||||||
if (prev_it == this->end()) {
|
if (prev_it == this->end()) {
|
||||||
FlowStat fs(via, flow);
|
FlowStat fs(via, flow);
|
||||||
fs.AppendShare(INVALID_STATION, flow);
|
fs.AppendShare(INVALID_STATION, flow);
|
||||||
this->insert(std::make_pair(origin, fs));
|
this->emplace(origin, fs);
|
||||||
} else {
|
} else {
|
||||||
prev_it->second.ChangeShare(via, flow);
|
prev_it->second.ChangeShare(via, flow);
|
||||||
prev_it->second.ChangeShare(INVALID_STATION, flow);
|
prev_it->second.ChangeShare(INVALID_STATION, flow);
|
||||||
|
|
Loading…
Reference in New Issue