Size game state guesser buffers first (#7905)

This commit is contained in:
2026-06-23 11:47:38 -07:00
committed by GitHub
parent 85d3ae8fce
commit ade5a4fa10
@@ -95,6 +95,7 @@ auto GuessMeteorTarget(
// Priority 3: Find a castle not occupied by the caster's player
// Build set of occupied coords by caster's player
std::unordered_set<int> casterOccupiedIndices;
casterOccupiedIndices.reserve(units.size());
for (const auto &unit : units) {
if (unit.player_id() == casterPlayerId) {
Coords loc = FromCoordsProto(unit.location());
@@ -163,10 +164,12 @@ auto GameStateGuesser::GuessedState(
auto statusDescription = fbb.CreateString(gameStateView.status().description());
std::vector<PlayerId> winningShardokIdsVec = {
std::begin(gameStateView.status().winning_shardok_ids()),
std::end(gameStateView.status().winning_shardok_ids())};
std::vector<PlayerId> winningShardokIdsVec;
winningShardokIdsVec.reserve(10);
winningShardokIdsVec.insert(
winningShardokIdsVec.end(),
std::begin(gameStateView.status().winning_shardok_ids()),
std::end(gameStateView.status().winning_shardok_ids()));
for (int i = gameStateView.status().winning_shardok_ids_size(); i < 10; i++) {
winningShardokIdsVec.push_back(-1);
}
@@ -350,10 +353,12 @@ auto GameStateGuesser::GuessedState(
auto unitsOffset = fbb.CreateVectorOfSortedStructs(&unitsVec);
auto chargeeIdsVec = std::vector<UnitId>(
std::vector<UnitId> chargeeIdsVec;
chargeeIdsVec.reserve(6);
chargeeIdsVec.insert(
chargeeIdsVec.end(),
std::begin(gameStateView.possible_chargee_ids()),
std::end(gameStateView.possible_chargee_ids()));
chargeeIdsVec.reserve(6);
for (int i = gameStateView.possible_chargee_ids_size(); i < 6; i++) {
chargeeIdsVec.push_back(-1);
}