1
0
Fork 0

Codechange: Let's use this new emplace_back() thing. (#13081)

pull/12699/merge
Peter Nelson 2024-11-15 20:28:17 +00:00 committed by GitHub
parent 98c8445519
commit 14e2839087
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 16 deletions

View File

@ -182,8 +182,7 @@ bool DLSFile::ReadDLSArticulation(FileHandle &f, DWORD list_length, std::vector<
bool DLSFile::ReadDLSRegion(FileHandle &f, DWORD list_length, std::vector<DLSRegion> &out) bool DLSFile::ReadDLSRegion(FileHandle &f, DWORD list_length, std::vector<DLSRegion> &out)
{ {
out.push_back(DLSRegion()); DLSRegion &region = out.emplace_back();
DLSRegion &region = out.back();
/* Set default values. */ /* Set default values. */
region.wave_sample.cbSize = 0; 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) bool DLSFile::ReadDLSInstrument(FileHandle &f, DWORD list_length)
{ {
this->instruments.push_back(DLSInstrument()); DLSInstrument &instrument = this->instruments.emplace_back();
DLSInstrument &instrument = this->instruments.back();
while (list_length > 0) { while (list_length > 0) {
ChunkHeader chunk; ChunkHeader chunk;
@ -339,8 +337,7 @@ bool DLSFile::ReadDLSInstrumentList(FileHandle &f, DWORD list_length)
bool DLSFile::ReadDLSWave(FileHandle &f, DWORD list_length, long offset) bool DLSFile::ReadDLSWave(FileHandle &f, DWORD list_length, long offset)
{ {
this->waves.push_back(DLSWave()); DLSWave &wave = this->waves.emplace_back();
DLSWave &wave = this->waves.back();
/* Set default values. */ /* Set default values. */
MemSetT(&wave.wave_sample, 0); MemSetT(&wave.wave_sample, 0);

View File

@ -210,8 +210,7 @@ static bool ReadTrackChunk(FileHandle &file, MidiFile &target)
return false; return false;
} }
target.blocks.push_back(MidiFile::DataBlock()); MidiFile::DataBlock *block = &target.blocks.emplace_back();
MidiFile::DataBlock *block = &target.blocks.back();
uint8_t last_status = 0; uint8_t last_status = 0;
bool running_sysex = false; bool running_sysex = false;
@ -222,8 +221,7 @@ static bool ReadTrackChunk(FileHandle &file, MidiFile &target)
return false; return false;
} }
if (deltatime > 0) { if (deltatime > 0) {
target.blocks.push_back(MidiFile::DataBlock(block->ticktime + deltatime)); block = &target.blocks.emplace_back(block->ticktime + deltatime);
block = &target.blocks.back();
} }
/* Read status byte */ /* Read status byte */
@ -792,8 +790,7 @@ struct MpsMachine {
* a maximum (about 10 minutes) avoids getting stuck, * a maximum (about 10 minutes) avoids getting stuck,
* in case of corrupted data. */ * in case of corrupted data. */
for (uint32_t tick = 0; tick < 100000; tick += 1) { for (uint32_t tick = 0; tick < 100000; tick += 1) {
this->target.blocks.push_back(MidiFile::DataBlock()); auto &block = this->target.blocks.emplace_back();
auto &block = this->target.blocks.back();
block.ticktime = tick; block.ticktime = tick;
if (!this->PlayFrame(block)) { if (!this->PlayFrame(block)) {
break; break;

View File

@ -3606,8 +3606,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop,
definition_size = UINT32_MAX; definition_size = UINT32_MAX;
} }
layout.push_back(IndustryTileLayoutTile{}); IndustryTileLayoutTile &it = layout.emplace_back();
IndustryTileLayoutTile &it = layout.back();
it.ti.x = buf.ReadByte(); // Offsets from northermost tile it.ti.x = buf.ReadByte(); // Offsets from northermost tile
++bytes_read; ++bytes_read;

View File

@ -77,8 +77,8 @@ public:
/* Build edge list from edge matrix. */ /* Build edge list from edge matrix. */
for (NodeID to = edges[_linkgraph_from].dest_node; to != INVALID_NODE; to = edges[to].dest_node) { for (NodeID to = edges[_linkgraph_from].dest_node; to != INVALID_NODE; to = edges[to].dest_node) {
bn->edges.push_back(edges[to]); auto &edge = bn->edges.emplace_back(edges[to]);
bn->edges.back().dest_node = to; edge.dest_node = to;
} }
/* Sort by destination. */ /* Sort by destination. */
std::sort(bn->edges.begin(), bn->edges.end()); std::sort(bn->edges.begin(), bn->edges.end());