mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use emplace_back instead of push_back. (#13855)
parent
b98a7ff303
commit
89948b941b
|
@ -106,7 +106,7 @@ void DumpDebugFacilityNames(std::back_insert_iterator<std::string> &output_itera
|
|||
* @param level Debug category.
|
||||
* @param message The message to output.
|
||||
*/
|
||||
void DebugPrint(const char *category, int level, const std::string &message)
|
||||
void DebugPrint(const char *category, int level, std::string &&message)
|
||||
{
|
||||
if (strcmp(category, "desync") == 0 && level != 0) {
|
||||
static auto f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
|
||||
|
@ -128,7 +128,7 @@ void DebugPrint(const char *category, int level, const std::string &message)
|
|||
if (_debug_remote_console.load()) {
|
||||
/* Only add to the queue when there is at least one consumer of the data. */
|
||||
std::lock_guard<std::mutex> lock(_debug_remote_console_mutex);
|
||||
_debug_remote_console_queue.push_back({ category, message });
|
||||
_debug_remote_console_queue.emplace_back(category, std::move(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
* @param format_string The formatting string of the message.
|
||||
*/
|
||||
#define Debug(category, level, format_string, ...) do { if ((level) == 0 || _debug_ ## category ## _level >= (level)) DebugPrint(#category, level, fmt::format(FMT_STRING(format_string) __VA_OPT__(,) __VA_ARGS__)); } while (false)
|
||||
void DebugPrint(const char *category, int level, const std::string &message);
|
||||
void DebugPrint(const char *category, int level, std::string &&message);
|
||||
|
||||
extern int _debug_driver_level;
|
||||
extern int _debug_grf_level;
|
||||
|
|
|
@ -237,7 +237,7 @@ void SetCurrentRailTypeLabelList()
|
|||
_railtype_list.clear();
|
||||
|
||||
for (RailType rt = RAILTYPE_BEGIN; rt != RAILTYPE_END; rt++) {
|
||||
_railtype_list.push_back({GetRailTypeInfo(rt)->label, 0});
|
||||
_railtype_list.emplace_back(GetRailTypeInfo(rt)->label, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ void SetCurrentRoadTypeLabelList()
|
|||
{
|
||||
_roadtype_list.clear();
|
||||
for (RoadType rt = ROADTYPE_BEGIN; rt != ROADTYPE_END; rt++) {
|
||||
_roadtype_list.push_back({GetRoadTypeInfo(rt)->label, GetRoadTramType(rt)});
|
||||
_roadtype_list.emplace_back(GetRoadTypeInfo(rt)->label, GetRoadTramType(rt));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -492,7 +492,7 @@ static void AddGRFTextToList(GRFTextList &list, uint8_t langid, std::string_view
|
|||
}
|
||||
|
||||
/* If a string wasn't replaced, then we must append the new string */
|
||||
list.push_back(GRFText{ langid, std::string(text_to_add) });
|
||||
list.emplace_back(langid, std::string{text_to_add});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -605,7 +605,7 @@ static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlags flags)
|
|||
break;
|
||||
}
|
||||
|
||||
_cleared_object_areas.push_back({tile, ta});
|
||||
_cleared_object_areas.emplace_back(tile, ta);
|
||||
|
||||
if (flags.Test(DoCommandFlag::Execute)) ReallyClearObjectTile(o);
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ public:
|
|||
void AddOrigin(const WaterRegionPatchDesc &water_region_patch)
|
||||
{
|
||||
if (water_region_patch.label == INVALID_WATER_REGION_PATCH) return;
|
||||
if (!HasOrigin(water_region_patch)) this->origin_keys.push_back(CYapfRegionPatchNodeKey{ water_region_patch });
|
||||
if (!HasOrigin(water_region_patch)) this->origin_keys.emplace_back(water_region_patch);
|
||||
}
|
||||
|
||||
bool HasOrigin(const WaterRegionPatchDesc &water_region_patch)
|
||||
|
|
|
@ -1903,7 +1903,7 @@ std::vector<SaveLoad> SlTableHeader(const SaveLoadTable &slt)
|
|||
}
|
||||
|
||||
/* We don't know this field, so read to nothing. */
|
||||
saveloads.push_back({std::move(key), saveload_type, ((VarType)type & SLE_FILE_TYPE_MASK) | SLE_VAR_NULL, 1, SL_MIN_VERSION, SL_MAX_VERSION, nullptr, 0, std::move(handler)});
|
||||
saveloads.emplace_back(std::move(key), saveload_type, ((VarType)type & SLE_FILE_TYPE_MASK) | SLE_VAR_NULL, 1, SL_MIN_VERSION, SL_MAX_VERSION, nullptr, 0, std::move(handler));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1917,7 +1917,7 @@ std::vector<SaveLoad> SlTableHeader(const SaveLoadTable &slt)
|
|||
Debug(sl, 1, "Field type for '{}' was expected to be 0x{:02x} but 0x{:02x} was found", key, correct_type, type);
|
||||
SlErrorCorrupt("Field type is different than expected");
|
||||
}
|
||||
saveloads.push_back(*sld_it->second);
|
||||
saveloads.emplace_back(*sld_it->second);
|
||||
}
|
||||
|
||||
for (auto &sld : saveloads) {
|
||||
|
@ -2010,7 +2010,7 @@ std::vector<SaveLoad> SlCompatTableHeader(const SaveLoadTable &slt, const SaveLo
|
|||
/* In old savegames there can be data we no longer care for. We
|
||||
* skip this by simply reading the amount of bytes indicated and
|
||||
* send those to /dev/null. */
|
||||
saveloads.push_back({"", SL_NULL, GetVarFileType(slc.null_type) | SLE_VAR_NULL, slc.null_length, slc.version_from, slc.version_to, nullptr, 0, nullptr});
|
||||
saveloads.emplace_back("", SL_NULL, GetVarFileType(slc.null_type) | SLE_VAR_NULL, slc.null_length, slc.version_from, slc.version_to, nullptr, 0, nullptr);
|
||||
} else {
|
||||
auto sld_it = key_lookup.find(slc.name);
|
||||
/* If this branch triggers, it means that an entry in the
|
||||
|
|
|
@ -84,7 +84,7 @@ static std::vector<SaveLoad> GetSettingsDesc(const SettingTable &settings, bool
|
|||
if (is_loading && sd->flags.Test(SettingFlag::NoNetworkSync) && _networking && !_network_server) {
|
||||
if (IsSavegameVersionBefore(SLV_TABLE_CHUNKS)) {
|
||||
/* We don't want to read this setting, so we do need to skip over it. */
|
||||
saveloads.push_back({sd->GetName(), sd->save.cmd, GetVarFileType(sd->save.conv) | SLE_VAR_NULL, sd->save.length, sd->save.version_from, sd->save.version_to, nullptr, 0, nullptr});
|
||||
saveloads.emplace_back(sd->GetName(), sd->save.cmd, GetVarFileType(sd->save.conv) | SLE_VAR_NULL, sd->save.length, sd->save.version_from, sd->save.version_to, nullptr, 0, nullptr);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -2248,7 +2248,7 @@ static const BaseStation *FindStationsNearby(TileArea ta, bool distant_join)
|
|||
if (T::IsValidBaseStation(st) && !st->IsInUse() && st->owner == _local_company) {
|
||||
/* Include only within station spread (yes, it is strictly less than) */
|
||||
if (std::max(DistanceMax(ta.tile, st->xy), DistanceMax(TileAddXY(ta.tile, ta.w - 1, ta.h - 1), st->xy)) < _settings_game.station.station_spread) {
|
||||
_deleted_stations_nearby.push_back({st->xy, st->index});
|
||||
_deleted_stations_nearby.emplace_back(st->xy, st->index);
|
||||
|
||||
/* Add the station when it's within where we're going to build */
|
||||
if (IsInsideBS(TileX(st->xy), TileX(ctx.tile), ctx.w) &&
|
||||
|
|
|
@ -558,7 +558,7 @@ ParsedCommandStruct ExtractCommandString(const char *s, bool)
|
|||
|
||||
p.consuming_commands[argidx++] = ar;
|
||||
} else if (!ar->flags.Test(CmdFlag::DontCount)) { // Ignore some of them
|
||||
p.non_consuming_commands.emplace_back(CmdPair{ar, std::move(param)});
|
||||
p.non_consuming_commands.emplace_back(ar, std::move(param));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -251,10 +251,7 @@ void TextfileWindow::FindHyperlinksInMarkdown(Line &line, size_t line_index)
|
|||
while (matcher != std::sregex_iterator()) {
|
||||
std::smatch match = *matcher;
|
||||
|
||||
Hyperlink link{};
|
||||
link.line = line_index;
|
||||
link.destination = match[2].str();
|
||||
this->links.push_back(link);
|
||||
Hyperlink &link = this->links.emplace_back(line_index, 0, 0, match[2].str());
|
||||
|
||||
HyperlinkType link_type = ClassifyHyperlink(link.destination, this->trusted);
|
||||
StringControlCode link_colour;
|
||||
|
@ -277,11 +274,11 @@ void TextfileWindow::FindHyperlinksInMarkdown(Line &line, size_t line_index)
|
|||
if (link_colour != SCC_CONTROL_END) {
|
||||
/* Format the link to look like a link. */
|
||||
fixed_line += std::string(last_match_end, match[0].first);
|
||||
this->links.back().begin = fixed_line.length();
|
||||
link.begin = fixed_line.length();
|
||||
fixed_line += std::string(ccbuf, Utf8Encode(ccbuf, SCC_PUSH_COLOUR));
|
||||
fixed_line += std::string(ccbuf, Utf8Encode(ccbuf, link_colour));
|
||||
fixed_line += match[1].str();
|
||||
this->links.back().end = fixed_line.length();
|
||||
link.end = fixed_line.length();
|
||||
fixed_line += std::string(ccbuf, Utf8Encode(ccbuf, SCC_POP_COLOUR));
|
||||
last_match_end = match[0].second;
|
||||
}
|
||||
|
@ -358,7 +355,7 @@ void TextfileWindow::AppendHistory(const std::string &filepath)
|
|||
{
|
||||
this->history.erase(this->history.begin() + this->history_pos + 1, this->history.end());
|
||||
this->UpdateHistoryScrollpos();
|
||||
this->history.push_back(HistoryEntry{ filepath, 0 });
|
||||
this->history.emplace_back(filepath, 0);
|
||||
this->EnableWidget(WID_TF_NAVBACK);
|
||||
this->DisableWidget(WID_TF_NAVFORWARD);
|
||||
this->history_pos = this->history.size() - 1;
|
||||
|
@ -519,7 +516,7 @@ void TextfileWindow::AfterLoadMarkdown()
|
|||
if (!line.text.empty() && line.text[0] == '#') {
|
||||
this->jumplist.push_back(line_index);
|
||||
this->lines[line_index].colour = TC_GOLD;
|
||||
this->link_anchors.emplace_back(Hyperlink{ line_index, 0, 0, MakeAnchorSlug(line.text) });
|
||||
this->link_anchors.emplace_back(line_index, 0, 0, MakeAnchorSlug(line.text));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -791,7 +788,7 @@ static std::vector<char> Xunzip(std::span<char> input)
|
|||
this->filepath = textfile;
|
||||
this->filename = this->filepath.substr(this->filepath.find_last_of(PATHSEP) + 1);
|
||||
/* If it's the first file being loaded, add to history. */
|
||||
if (this->history.empty()) this->history.push_back(HistoryEntry{ this->filepath, 0 });
|
||||
if (this->history.empty()) this->history.emplace_back(this->filepath, 0);
|
||||
|
||||
/* Process the loaded text into lines, and do any further parsing needed. */
|
||||
this->LoadText(sv_buf);
|
||||
|
|
|
@ -717,7 +717,7 @@ CommandCost CmdBuildTunnel(DoCommandFlags flags, TileIndex start_tile, Transport
|
|||
* Do this for all tiles (like trees), not only objects. */
|
||||
ClearedObjectArea *coa = FindClearedObject(end_tile);
|
||||
if (coa == nullptr) {
|
||||
coa = &_cleared_object_areas.emplace_back(ClearedObjectArea{ end_tile, TileArea(end_tile, 1, 1) });
|
||||
coa = &_cleared_object_areas.emplace_back(end_tile, TileArea(end_tile, 1, 1));
|
||||
}
|
||||
|
||||
/* Hide the tile from the terraforming command */
|
||||
|
|
|
@ -463,7 +463,7 @@ static std::tuple<CommandCost, uint, uint16_t, CargoArray> RefitVehicle(Vehicle
|
|||
* - We have to call the refit cost callback with the pre-refit configuration of the chain because we want refit and
|
||||
* autorefit to behave the same, and we need its result for auto_refit_allowed.
|
||||
*/
|
||||
refit_result.push_back({v, amount, mail_capacity, actual_subtype});
|
||||
refit_result.emplace_back(v, amount, mail_capacity, actual_subtype);
|
||||
}
|
||||
|
||||
if (flags.Test(DoCommandFlag::Execute)) {
|
||||
|
|
|
@ -795,7 +795,7 @@ struct RefitWindow : public Window {
|
|||
bool first_vehicle = list.empty();
|
||||
if (first_vehicle) {
|
||||
/* Keeping the current subtype is always an option. It also serves as the option in case of no subtypes */
|
||||
list.push_back({cargo_type, UINT8_MAX, STR_EMPTY});
|
||||
list.emplace_back(cargo_type, UINT8_MAX, STR_EMPTY);
|
||||
}
|
||||
|
||||
/* Check the vehicle's callback mask for cargo suffixes.
|
||||
|
@ -823,10 +823,7 @@ struct RefitWindow : public Window {
|
|||
/* Append new subtype (don't add duplicates though) */
|
||||
if (subtype == STR_EMPTY) break;
|
||||
|
||||
RefitOption option;
|
||||
option.cargo = cargo_type;
|
||||
option.subtype = refit_cyc;
|
||||
option.string = subtype;
|
||||
RefitOption option{cargo_type, static_cast<uint8_t>(refit_cyc), subtype};
|
||||
include(list, option);
|
||||
} else {
|
||||
/* Intersect the subtypes of earlier vehicles with the subtypes of this vehicle */
|
||||
|
@ -835,7 +832,7 @@ struct RefitWindow : public Window {
|
|||
/* UINT8_MAX item is in front, other subtypes are sorted. So just truncate the list in the right spot */
|
||||
for (uint i = 1; i < list.size(); i++) {
|
||||
if (list[i].subtype >= refit_cyc) {
|
||||
list.resize(i);
|
||||
list.erase(list.begin() + i, list.end());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue