diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-07-24 00:55:26 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-24 01:40:51 +0200 |
commit | d76b42599ebfbf2f70575c379fb659ca74e44320 (patch) | |
tree | 4f93abc1a03dccbd2ea8c0d686b2109401f2af72 /Userland/Games/Hearts/Game.cpp | |
parent | 5201c17d9b571d58a0e7b1e5bb140ddf39b379a2 (diff) | |
download | serenity-d76b42599ebfbf2f70575c379fb659ca74e44320.zip |
Hearts: Avoid reallocations for Vectors when possible
Diffstat (limited to 'Userland/Games/Hearts/Game.cpp')
-rw-r--r-- | Userland/Games/Hearts/Game.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp index 5ef03979b0..cb023b95a9 100644 --- a/Userland/Games/Hearts/Game.cpp +++ b/Userland/Games/Hearts/Game.cpp @@ -203,6 +203,7 @@ void Game::setup(String player_name, int hand_number) } NonnullRefPtrVector<Card> deck; + deck.ensure_capacity(Card::card_count * 4); for (int i = 0; i < Card::card_count; ++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) { + player.hand.ensure_capacity(Card::card_count); for (uint8_t i = 0; i < Card::card_count; ++i) { auto card = deck.take(get_random_uniform(deck.size())); if constexpr (!HEARTS_DEBUG) { |