From 14e2839087c4f579aaf32ac1468c344ecbd1f60b Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 15 Nov 2024 20:28:17 +0000 Subject: [PATCH] Codechange: Let's use this new emplace_back() thing. (#13081) --- src/music/dmusic.cpp | 9 +++------ src/music/midifile.cpp | 9 +++------ src/newgrf.cpp | 3 +-- src/saveload/linkgraph_sl.cpp | 4 ++-- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/music/dmusic.cpp b/src/music/dmusic.cpp index 9028ac00c4..54d5200115 100644 --- a/src/music/dmusic.cpp +++ b/src/music/dmusic.cpp @@ -182,8 +182,7 @@ bool DLSFile::ReadDLSArticulation(FileHandle &f, DWORD list_length, std::vector< bool DLSFile::ReadDLSRegion(FileHandle &f, DWORD list_length, std::vector &out) { - out.push_back(DLSRegion()); - DLSRegion ®ion = out.back(); + DLSRegion ®ion = out.emplace_back(); /* Set default values. */ region.wave_sample.cbSize = 0; @@ -267,8 +266,7 @@ bool DLSFile::ReadDLSRegionList(FileHandle &f, DWORD list_length, DLSInstrument bool DLSFile::ReadDLSInstrument(FileHandle &f, DWORD list_length) { - this->instruments.push_back(DLSInstrument()); - DLSInstrument &instrument = this->instruments.back(); + DLSInstrument &instrument = this->instruments.emplace_back(); while (list_length > 0) { ChunkHeader chunk; @@ -339,8 +337,7 @@ bool DLSFile::ReadDLSInstrumentList(FileHandle &f, DWORD list_length) bool DLSFile::ReadDLSWave(FileHandle &f, DWORD list_length, long offset) { - this->waves.push_back(DLSWave()); - DLSWave &wave = this->waves.back(); + DLSWave &wave = this->waves.emplace_back(); /* Set default values. */ MemSetT(&wave.wave_sample, 0); diff --git a/src/music/midifile.cpp b/src/music/midifile.cpp index a030fa33d3..e3ebce3e74 100644 --- a/src/music/midifile.cpp +++ b/src/music/midifile.cpp @@ -210,8 +210,7 @@ static bool ReadTrackChunk(FileHandle &file, MidiFile &target) return false; } - target.blocks.push_back(MidiFile::DataBlock()); - MidiFile::DataBlock *block = &target.blocks.back(); + MidiFile::DataBlock *block = &target.blocks.emplace_back(); uint8_t last_status = 0; bool running_sysex = false; @@ -222,8 +221,7 @@ static bool ReadTrackChunk(FileHandle &file, MidiFile &target) return false; } if (deltatime > 0) { - target.blocks.push_back(MidiFile::DataBlock(block->ticktime + deltatime)); - block = &target.blocks.back(); + block = &target.blocks.emplace_back(block->ticktime + deltatime); } /* Read status byte */ @@ -792,8 +790,7 @@ struct MpsMachine { * a maximum (about 10 minutes) avoids getting stuck, * in case of corrupted data. */ for (uint32_t tick = 0; tick < 100000; tick += 1) { - this->target.blocks.push_back(MidiFile::DataBlock()); - auto &block = this->target.blocks.back(); + auto &block = this->target.blocks.emplace_back(); block.ticktime = tick; if (!this->PlayFrame(block)) { break; diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 72176bcb87..202c350174 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3606,8 +3606,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, definition_size = UINT32_MAX; } - layout.push_back(IndustryTileLayoutTile{}); - IndustryTileLayoutTile &it = layout.back(); + IndustryTileLayoutTile &it = layout.emplace_back(); it.ti.x = buf.ReadByte(); // Offsets from northermost tile ++bytes_read; diff --git a/src/saveload/linkgraph_sl.cpp b/src/saveload/linkgraph_sl.cpp index 9295302abd..e9e1ac0198 100644 --- a/src/saveload/linkgraph_sl.cpp +++ b/src/saveload/linkgraph_sl.cpp @@ -77,8 +77,8 @@ public: /* Build edge list from edge matrix. */ for (NodeID to = edges[_linkgraph_from].dest_node; to != INVALID_NODE; to = edges[to].dest_node) { - bn->edges.push_back(edges[to]); - bn->edges.back().dest_node = to; + auto &edge = bn->edges.emplace_back(edges[to]); + edge.dest_node = to; } /* Sort by destination. */ std::sort(bn->edges.begin(), bn->edges.end());