Changeset - r24434:1f13cf59de8a
[Not reviewed]
master
0 14 0
Michael Lutz - 4 years ago 2020-12-14 23:22:04
michi@icosahedron.de
Codechange: Make use of the improved C++17 emplace_back function.
14 files changed with 22 insertions and 44 deletions:
0 comments (0 inline, 0 general)
src/bridge_gui.cpp
Show inline comments
 
@@ -433,8 +433,7 @@ void ShowBuildBridgeWindow(TileIndex sta
 
			type_check = CheckBridgeAvailability(brd_type, bridge_len);
 
			if (type_check.Succeeded()) {
 
				/* bridge is accepted, add to list */
 
				/*C++17: BuildBridgeData &item = */ bl->emplace_back();
 
				BuildBridgeData &item = bl->back();
 
				BuildBridgeData &item = bl->emplace_back();
 
				item.index = brd_type;
 
				item.spec = GetBridgeSpec(brd_type);
 
				/* Add to terraforming & bulldozing costs the cost of the
src/core/smallmap_type.hpp
Show inline comments
 
@@ -142,8 +142,7 @@ struct SmallMap : std::vector<std::pair<
 
		for (uint i = 0; i < std::vector<Pair>::size(); i++) {
 
			if (key == std::vector<Pair>::operator[](i).first) return std::vector<Pair>::operator[](i).second;
 
		}
 
		/*C++17: Pair &n = */ std::vector<Pair>::emplace_back();
 
		Pair &n = std::vector<Pair>::back();
 
		Pair &n = std::vector<Pair>::emplace_back();
 
		n.first = key;
 
		return n.second;
 
	}
src/engine.cpp
Show inline comments
 
@@ -486,8 +486,7 @@ void EngineOverrideManager::ResetToDefau
 
	this->clear();
 
	for (VehicleType type = VEH_TRAIN; type <= VEH_AIRCRAFT; type++) {
 
		for (uint internal_id = 0; internal_id < _engine_counts[type]; internal_id++) {
 
			/*C++17: EngineIDMapping &eid = */ this->emplace_back();
 
			EngineIDMapping &eid = this->back();
 
			EngineIDMapping &eid = this->emplace_back();
 
			eid.type            = type;
 
			eid.grfid           = INVALID_GRFID;
 
			eid.internal_id     = internal_id;
src/fios.h
Show inline comments
 
@@ -119,8 +119,7 @@ public:
 
	 */
 
	inline FiosItem *Append()
 
	{
 
		/*C++17: return &*/ this->files.emplace_back();
 
		return &this->files.back();
 
		return &this->files.emplace_back();
 
	}
 

	
 
	/**
src/industry_gui.cpp
Show inline comments
 
@@ -2625,8 +2625,7 @@ struct IndustryCargoesWindow : public Wi
 
		_displayed_industries.set(it);
 

	
 
		this->fields.clear();
 
		/*C++17: CargoesRow &row = */ this->fields.emplace_back();
 
		CargoesRow &row = this->fields.back();
 
		CargoesRow &row = this->fields.emplace_back();
 
		row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
 
		row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
 
		row.columns[2].MakeEmpty(CFT_SMALL_EMPTY);
 
@@ -2641,8 +2640,7 @@ struct IndustryCargoesWindow : public Wi
 
		int num_cust = CountMatchingAcceptingIndustries(central_sp->produced_cargo, lengthof(central_sp->produced_cargo)) + houses_accept;
 
		int num_indrows = max(3, max(num_supp, num_cust)); // One is needed for the 'it' industry, and 2 for the cargo labels.
 
		for (int i = 0; i < num_indrows; i++) {
 
			/*C++17: CargoesRow &row = */ this->fields.emplace_back();
 
			CargoesRow &row = this->fields.back();
 
			CargoesRow &row = this->fields.emplace_back();
 
			row.columns[0].MakeEmpty(CFT_EMPTY);
 
			row.columns[1].MakeCargo(central_sp->accepts_cargo, lengthof(central_sp->accepts_cargo));
 
			row.columns[2].MakeEmpty(CFT_EMPTY);
 
@@ -2705,8 +2703,7 @@ struct IndustryCargoesWindow : public Wi
 
		_displayed_industries.reset();
 

	
 
		this->fields.clear();
 
		/*C++17: CargoesRow &row = */ this->fields.emplace_back();
 
		CargoesRow &row = this->fields.back();
 
		CargoesRow &row = this->fields.emplace_back();
 
		row.columns[0].MakeHeader(STR_INDUSTRY_CARGOES_PRODUCERS);
 
		row.columns[1].MakeEmpty(CFT_SMALL_EMPTY);
 
		row.columns[2].MakeHeader(STR_INDUSTRY_CARGOES_CUSTOMERS);
 
@@ -2719,8 +2716,7 @@ struct IndustryCargoesWindow : public Wi
 
		int num_cust = CountMatchingAcceptingIndustries(&cid, 1) + houses_accept;
 
		int num_indrows = max(num_supp, num_cust);
 
		for (int i = 0; i < num_indrows; i++) {
 
			/*C++17: CargoesRow &row = */ this->fields.emplace_back();
 
			CargoesRow &row = this->fields.back();
 
			CargoesRow &row = this->fields.emplace_back();
 
			row.columns[0].MakeEmpty(CFT_EMPTY);
 
			row.columns[1].MakeCargo(&cid, 1);
 
			row.columns[2].MakeEmpty(CFT_EMPTY);
src/newgrf.cpp
Show inline comments
 
@@ -1916,8 +1916,7 @@ static ChangeInfoResult StationChangeInf
 
					tmp_layout.clear();
 
					for (;;) {
 
						/* no relative bounding box support */
 
						/*C++17: DrawTileSeqStruct &dtss = */ tmp_layout.emplace_back();
 
						DrawTileSeqStruct &dtss = tmp_layout.back();
 
						DrawTileSeqStruct &dtss = tmp_layout.emplace_back();
 
						MemSetT(&dtss, 0);
 

	
 
						dtss.delta_x = buf->ReadByte();
 
@@ -5020,8 +5019,7 @@ static void NewSpriteGroup(ByteReader *b
 
			/* Loop through the var adjusts. Unfortunately we don't know how many we have
 
			 * from the outset, so we shall have to keep reallocing. */
 
			do {
 
				/*C++17: DeterministicSpriteGroupAdjust &adjust = */ adjusts.emplace_back();
 
				DeterministicSpriteGroupAdjust &adjust = adjusts.back();
 
				DeterministicSpriteGroupAdjust &adjust = adjusts.emplace_back();
 

	
 
				/* The first var adjust doesn't have an operation specified, so we set it to add. */
 
				adjust.operation = adjusts.size() == 1 ? DSGA_OP_ADD : (DeterministicSpriteGroupAdjustOperation)buf->ReadByte();
src/newgrf_commons.cpp
Show inline comments
 
@@ -664,8 +664,7 @@ uint32 NewGRFSpriteLayout::PrepareLayout
 

	
 
	/* Create a copy of the spritelayout, so we can modify some values.
 
	 * Also include the groundsprite into the sequence for easier processing. */
 
	/*C++17: DrawTileSeqStruct *result = &*/ result_seq.emplace_back();
 
	DrawTileSeqStruct *result = &result_seq.back();
 
	DrawTileSeqStruct *result = &result_seq.emplace_back();
 
	result->image = ground;
 
	result->delta_x = 0;
 
	result->delta_y = 0;
 
@@ -675,8 +674,7 @@ uint32 NewGRFSpriteLayout::PrepareLayout
 
	foreach_draw_tile_seq(dtss, this->seq) {
 
		result_seq.push_back(*dtss);
 
	}
 
	result_seq.emplace_back() /*C++17: .MakeTerminator()*/;
 
	result_seq.back().MakeTerminator();
 
	result_seq.emplace_back().MakeTerminator();
 
	/* Determine the var10 values the action-1-2-3 chains needs to be resolved for,
 
	 * and apply the default sprite offsets (unless disabled). */
 
	const TileLayoutRegisters *regs = this->registers;
src/saveload/afterload.cpp
Show inline comments
 
@@ -2924,8 +2924,7 @@ bool AfterLoadGame()
 
					cur_skip = prev_tile_skip;
 
				}
 

	
 
				/*C++17: uint &this_skip = */ skip_frames.push_back(prev_tile_skip);
 
				uint &this_skip = skip_frames.back();
 
				uint &this_skip = skip_frames.emplace_back(prev_tile_skip);
 

	
 
				/* The following 3 curves now take longer than before */
 
				switch (u->state) {
src/saveload/engine_sl.cpp
Show inline comments
 
@@ -191,8 +191,7 @@ static void Load_EIDS()
 
	_engine_mngr.clear();
 

	
 
	while (SlIterateArray() != -1) {
 
		/*C++17: EngineIDMapping *eid = &*/ _engine_mngr.emplace_back();
 
		EngineIDMapping *eid = &_engine_mngr.back();
 
		EngineIDMapping *eid = &_engine_mngr.emplace_back();
 
		SlObject(eid, _engine_id_mapping_desc);
 
	}
 
}
src/saveload/waypoint_sl.cpp
Show inline comments
 
@@ -192,8 +192,7 @@ static void Load_WAYP()
 
	int index;
 

	
 
	while ((index = SlIterateArray()) != -1) {
 
		/*C++17: OldWaypoint *wp = &*/ _old_waypoints.emplace_back();
 
		OldWaypoint *wp = &_old_waypoints.back();
 
		OldWaypoint *wp = &_old_waypoints.emplace_back();
 

	
 
		wp->index = index;
 
		SlObject(wp, _old_waypoint_desc);
src/settingsgen/settingsgen.cpp
Show inline comments
 
@@ -118,8 +118,7 @@ public:
 
			text += stored_size;
 
		}
 
		while (length > 0) {
 
			/*C++17: OutputBuffer &block =*/ this->output_buffer.emplace_back();
 
			OutputBuffer &block = this->output_buffer.back();
 
			OutputBuffer &block = this->output_buffer.emplace_back();
 
			block.Clear(); // Initialize the new block.
 
			size_t stored_size = block.Add(text, length);
 
			length -= stored_size;
src/stringfilter.cpp
Show inline comments
 
@@ -74,8 +74,7 @@ void StringFilter::SetFilterTerm(const c
 

	
 
		/* Add to word */
 
		if (word == nullptr) {
 
			/*C++17: word = &*/ this->word_index.push_back({dest, false});
 
			word = &this->word_index.back();
 
			word = &this->word_index.emplace_back(WordState{ dest, false });
 
		}
 

	
 
		memcpy(dest, pos, len);
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -710,8 +710,7 @@ CommandCost CmdBuildTunnel(TileIndex sta
 
		 * Do this for all tiles (like trees), not only objects. */
 
		ClearedObjectArea *coa = FindClearedObject(end_tile);
 
		if (coa == nullptr) {
 
			/*C++17: coa = &*/ _cleared_object_areas.push_back({end_tile, TileArea(end_tile, 1, 1)});
 
			coa = &_cleared_object_areas.back();
 
			coa = &_cleared_object_areas.emplace_back(ClearedObjectArea{ end_tile, TileArea(end_tile, 1, 1) });
 
		}
 

	
 
		/* Hide the tile from the terraforming command */
src/viewport.cpp
Show inline comments
 
@@ -498,8 +498,7 @@ static void AddTileSpriteToDraw(SpriteID
 
{
 
	assert((image & SPRITE_MASK) < MAX_SPRITES);
 

	
 
	/*C++17: TileSpriteToDraw &ts = */ _vd.tile_sprites_to_draw.emplace_back();
 
	TileSpriteToDraw &ts = _vd.tile_sprites_to_draw.back();
 
	TileSpriteToDraw &ts = _vd.tile_sprites_to_draw.emplace_back();
 
	ts.image = image;
 
	ts.pal = pal;
 
	ts.sub = sub;
 
@@ -708,8 +707,7 @@ void AddSortableSpriteToDraw(SpriteID im
 
		return;
 
	}
 

	
 
	/*C++17: ParentSpriteToDraw &ps = */ _vd.parent_sprites_to_draw.emplace_back();
 
	ParentSpriteToDraw &ps = _vd.parent_sprites_to_draw.back();
 
	ParentSpriteToDraw &ps = _vd.parent_sprites_to_draw.emplace_back();
 
	ps.x = tmp_x;
 
	ps.y = tmp_y;
 

	
 
@@ -827,8 +825,7 @@ void AddChildSpriteScreen(SpriteID image
 

	
 
	*_vd.last_child = (uint)_vd.child_screen_sprites_to_draw.size();
 

	
 
	/*C++17: ChildScreenSpriteToDraw &cs = */ _vd.child_screen_sprites_to_draw.emplace_back();
 
	ChildScreenSpriteToDraw &cs = _vd.child_screen_sprites_to_draw.back();
 
	ChildScreenSpriteToDraw &cs = _vd.child_screen_sprites_to_draw.emplace_back();
 
	cs.image = image;
 
	cs.pal = pal;
 
	cs.sub = sub;
 
@@ -847,8 +844,7 @@ void AddChildSpriteScreen(SpriteID image
 
static void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, Colours colour, uint16 width)
 
{
 
	assert(width != 0);
 
	/*C++17: StringSpriteToDraw &ss = */ _vd.string_sprites_to_draw.emplace_back();
 
	StringSpriteToDraw &ss = _vd.string_sprites_to_draw.back();
 
	StringSpriteToDraw &ss = _vd.string_sprites_to_draw.emplace_back();
 
	ss.string = string;
 
	ss.x = x;
 
	ss.y = y;
0 comments (0 inline, 0 general)