mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 11:03:54 -07:00
[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:
parent
f16c552d97
commit
746f2af044
6 changed files with 67 additions and 76 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue