[DeckListModel] optimize by iterating over cardNodes instead of ExactCards (#6485)

* [DeckListModel] optimize by iterating over cardNodes instead of ExactCards

* fix build failure

* another optimization

* fix build failure
This commit is contained in:
RickyRister 2026-01-03 19:19:04 -08:00 committed by GitHub
parent f16c552d97
commit 746f2af044
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 67 additions and 76 deletions

View file

@ -608,35 +608,6 @@ void DeckListModel::forEachCard(const std::function<void(InnerDecklistNode *, De
deckList->forEachCard(func);
}
static QList<ExactCard> cardNodesToExactCards(QList<const DecklistCardNode *> nodes)
{
QList<ExactCard> cards;
for (auto node : nodes) {
ExactCard card = CardDatabaseManager::query()->getCard(node->toCardRef());
if (card) {
for (int k = 0; k < node->getNumber(); ++k) {
cards.append(card);
}
} else {
qDebug() << "Card not found in database!";
}
}
return cards;
}
QList<ExactCard> DeckListModel::getCards() const
{
auto nodes = deckList->getCardNodes();
return cardNodesToExactCards(nodes);
}
QList<ExactCard> DeckListModel::getCardsForZone(const QString &zoneName) const
{
auto nodes = deckList->getCardNodes({zoneName});
return cardNodesToExactCards(nodes);
}
QList<const DecklistCardNode *> DeckListModel::getCardNodes() const
{
return deckList->getCardNodes();

View file

@ -329,16 +329,6 @@ public:
*/
void forEachCard(const std::function<void(InnerDecklistNode *, DecklistCardNode *)> &func);
/**
* @brief Creates a list consisting of the entries of the model mapped into ExactCards (with each entry looked up
* in the card database).
* If a card node has number > 1, it will be added that many times to the list.
* If an entry's card is not found in the card database, that entry will be left out of the list.
* @return An ordered list of ExactCards
*/
[[nodiscard]] QList<ExactCard> getCards() const;
[[nodiscard]] QList<ExactCard> getCardsForZone(const QString &zoneName) const;
/**
* @brief Gets a list of all card nodes in the deck.
*/