From d8f19fdda2c7c74dd7095e1781883d997cbafebe Mon Sep 17 00:00:00 2001 From: leriomaggio Date: Wed, 25 Aug 2021 12:28:13 +0100 Subject: [PATCH] First CardDb optimisation - reusing same strategy for lazyLoading There was a FIXME/TODO comment I just have found out relating to putCard implementation being inefficient. I've re-used the new-methods implemented for lazyCardLoading to improve existing implementation. Also, now all the PaperCard constructors won't miss collectorNumber and ArtistNames as gathered from CardInSet in CardEdition - YAY --- .../src/main/java/forge/card/CardDb.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/forge-core/src/main/java/forge/card/CardDb.java b/forge-core/src/main/java/forge/card/CardDb.java index f573c618792..a1dd0cc8b98 100644 --- a/forge-core/src/main/java/forge/card/CardDb.java +++ b/forge-core/src/main/java/forge/card/CardDb.java @@ -1006,29 +1006,33 @@ public final class CardDb implements ICardDatabase, IDeckGenPool { // 1. generate all paper cards from edition data we have (either explicit, or found in res/editions, or add to unknown edition) List paperCards = new ArrayList<>(); if (null == whenItWasPrinted || whenItWasPrinted.isEmpty()) { - // TODO Not performant Each time we "putCard" we loop through ALL CARDS IN ALL editions + // @friarsol: Not performant Each time we "putCard" we loop through ALL CARDS IN ALL editions + // @leriomaggio: DONE! re-using here the same strategy implemented for lazy-loading! for (CardEdition e : editions.getOrderedEditions()) { int artIdx = IPaperCard.DEFAULT_ART_INDEX; - for (CardInSet cis : e.getAllCardsInSet()) { - if (!cis.name.equals(cardName)) { - continue; - } - paperCards.add(new PaperCard(rules, e.getCode(), cis.rarity, artIdx++)); - } + for (CardInSet cis : e.getCardInSet(cardName)) + paperCards.add(new PaperCard(rules, e.getCode(), cis.rarity, artIdx++, false, + cis.collectorNumber, cis.artistName)); } } else { String lastEdition = null; int artIdx = 0; for (Pair tuple : whenItWasPrinted) { if (!tuple.getKey().equals(lastEdition)) { - artIdx = IPaperCard.DEFAULT_ART_INDEX; + artIdx = IPaperCard.DEFAULT_ART_INDEX; // reset artIndex lastEdition = tuple.getKey(); } CardEdition ed = editions.get(lastEdition); - if (null == ed) { + if (ed == null) { continue; } - paperCards.add(new PaperCard(rules, lastEdition, tuple.getValue(), artIdx++)); + List cardsInSet = ed.getCardInSet(cardName); + if (cardsInSet.isEmpty()) + continue; + int cardInSetIndex = Math.max(artIdx-1, 0); // make sure doesn't go below zero + CardInSet cds = cardsInSet.get(cardInSetIndex); // use ArtIndex to get the right Coll. Number + paperCards.add(new PaperCard(rules, lastEdition, tuple.getValue(), artIdx++, false, + cds.collectorNumber, cds.artistName)); } } if (paperCards.isEmpty()) {