Codechange: Emplace std::pair into vectors.

This creates the pair in the vector, instead of creating it then copying it in.
This commit is contained in:
Peter Nelson 2024-04-20 02:48:56 +01:00 committed by Peter Nelson
parent ed2db80990
commit 40fa45a76a
7 changed files with 8 additions and 8 deletions

View File

@ -293,7 +293,7 @@ private:
for (uint i = 0; i != elements.size(); i++) { for (uint i = 0; i != elements.size(); i++) {
auto *lte = elements[i]; auto *lte = elements[i];
if (i > 0 && elements[i - 1]->rating != lte->rating) rank = i; if (i > 0 && elements[i - 1]->rating != lte->rating) rank = i;
this->rows.emplace_back(std::make_pair(rank, lte)); this->rows.emplace_back(rank, lte);
} }
} }

View File

@ -113,7 +113,7 @@ void LinkGraphOverlay::RebuildCache()
} }
} }
if (this->IsPointVisible(pta, &dpi)) { if (this->IsPointVisible(pta, &dpi)) {
this->cached_stations.push_back(std::make_pair(from, supply)); this->cached_stations.emplace_back(from, supply);
} }
} }
} }

View File

@ -71,7 +71,7 @@ public:
} }
/* Insert new item. */ /* Insert new item. */
this->data.push_front(std::make_pair(key, item)); this->data.emplace_front(key, item);
this->lookup.emplace(key, this->data.begin()); this->lookup.emplace(key, this->data.begin());
} }

View File

@ -4225,9 +4225,9 @@ uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, Sourc
} }
if (used_stations.empty()) { if (used_stations.empty()) {
used_stations.reserve(2); used_stations.reserve(2);
used_stations.emplace_back(std::make_pair(first_station, 0)); used_stations.emplace_back(first_station, 0);
} }
used_stations.emplace_back(std::make_pair(st, 0)); used_stations.emplace_back(st, 0);
} }
/* no stations around at all? */ /* no stations around at all? */

View File

@ -2717,7 +2717,7 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
uint cur_prob = hs.probability; uint cur_prob = hs.probability;
probability_max += cur_prob; probability_max += cur_prob;
probs.emplace_back(std::make_pair(hs.Index(), cur_prob)); probs.emplace_back(hs.Index(), cur_prob);
} }
TileIndex baseTile = tile; TileIndex baseTile = tile;

View File

@ -1545,7 +1545,7 @@ static void ViewportSortParentSprites(ParentSpriteToSortVector *psdv)
/* Initialize sprite list and order. */ /* Initialize sprite list and order. */
for (auto p = psdv->rbegin(); p != psdv->rend(); p++) { for (auto p = psdv->rbegin(); p != psdv->rend(); p++) {
sprite_list.push_front(std::make_pair((*p)->xmin + (*p)->ymin, *p)); sprite_list.emplace_front((*p)->xmin + (*p)->ymin, *p);
sprite_order.push(*p); sprite_order.push(*p);
(*p)->order = next_order++; (*p)->order = next_order++;
} }

View File

@ -48,7 +48,7 @@ void ViewportSortParentSpritesSSE41(ParentSpriteToSortVector *psdv)
/* Initialize sprite list and order. */ /* Initialize sprite list and order. */
for (auto p = psdv->rbegin(); p != psdv->rend(); p++) { for (auto p = psdv->rbegin(); p != psdv->rend(); p++) {
sprite_list.push_front(std::make_pair((*p)->xmin + (*p)->ymin, *p)); sprite_list.emplace_front((*p)->xmin + (*p)->ymin, *p);
sprite_order.push(*p); sprite_order.push(*p);
(*p)->order = next_order++; (*p)->order = next_order++;
} }