diff --git a/src/debug.cpp b/src/debug.cpp index 96764893b6..fd8d7581e5 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -106,7 +106,7 @@ void DumpDebugFacilityNames(std::back_insert_iterator &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 lock(_debug_remote_console_mutex); - _debug_remote_console_queue.push_back({ category, message }); + _debug_remote_console_queue.emplace_back(category, std::move(message)); } } } diff --git a/src/debug.h b/src/debug.h index 8e4dc795ce..378466450c 100644 --- a/src/debug.h +++ b/src/debug.h @@ -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; diff --git a/src/newgrf_railtype.cpp b/src/newgrf_railtype.cpp index 20865e33be..8c4b5b8a1d 100644 --- a/src/newgrf_railtype.cpp +++ b/src/newgrf_railtype.cpp @@ -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); } } diff --git a/src/newgrf_roadtype.cpp b/src/newgrf_roadtype.cpp index 01e40f3e76..1b91571444 100644 --- a/src/newgrf_roadtype.cpp +++ b/src/newgrf_roadtype.cpp @@ -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)); } } diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index 77fcff45f4..d448019dba 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -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}); } /** diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index 888634ee38..94af931e8a 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -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); diff --git a/src/pathfinder/yapf/yapf_ship_regions.cpp b/src/pathfinder/yapf/yapf_ship_regions.cpp index e27d063634..441cd1cda9 100644 --- a/src/pathfinder/yapf/yapf_ship_regions.cpp +++ b/src/pathfinder/yapf/yapf_ship_regions.cpp @@ -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) diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 6b786f8d38..cfbb950de3 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -1903,7 +1903,7 @@ std::vector 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 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 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 diff --git a/src/saveload/settings_sl.cpp b/src/saveload/settings_sl.cpp index c36b0dd4c0..96e50ecc9a 100644 --- a/src/saveload/settings_sl.cpp +++ b/src/saveload/settings_sl.cpp @@ -84,7 +84,7 @@ static std::vector 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; } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 30a961b7e7..e7b3a224fd 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -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) && diff --git a/src/strgen/strgen_base.cpp b/src/strgen/strgen_base.cpp index b369415834..57a819981d 100644 --- a/src/strgen/strgen_base.cpp +++ b/src/strgen/strgen_base.cpp @@ -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)); } } diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp index 0f7f3a4fe2..3d8bdbcf1a 100644 --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -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 Xunzip(std::span 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); diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 6377b48555..5f8fc61573 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -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 */ diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 5845e58f0c..6a3a889f22 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -463,7 +463,7 @@ static std::tuple 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)) { diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index c801a91a75..2126b767f5 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -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(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; } }