mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:37:45 +00:00
Hearts: Avoid reallocations for Vectors when possible
This commit is contained in:
parent
5201c17d9b
commit
d76b42599e
1 changed files with 2 additions and 0 deletions
|
@ -203,6 +203,7 @@ void Game::setup(String player_name, int hand_number)
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtrVector<Card> deck;
|
NonnullRefPtrVector<Card> deck;
|
||||||
|
deck.ensure_capacity(Card::card_count * 4);
|
||||||
|
|
||||||
for (int i = 0; i < Card::card_count; ++i) {
|
for (int i = 0; i < Card::card_count; ++i) {
|
||||||
deck.append(Card::construct(Card::Type::Clubs, i));
|
deck.append(Card::construct(Card::Type::Clubs, i));
|
||||||
|
@ -212,6 +213,7 @@ void Game::setup(String player_name, int hand_number)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& player : m_players) {
|
for (auto& player : m_players) {
|
||||||
|
player.hand.ensure_capacity(Card::card_count);
|
||||||
for (uint8_t i = 0; i < Card::card_count; ++i) {
|
for (uint8_t i = 0; i < Card::card_count; ++i) {
|
||||||
auto card = deck.take(get_random_uniform(deck.size()));
|
auto card = deck.take(get_random_uniform(deck.size()));
|
||||||
if constexpr (!HEARTS_DEBUG) {
|
if constexpr (!HEARTS_DEBUG) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue