mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Still scratching a little of performance impros by avoiding checking class instance.
When StatTypeFilter is used withing Deck Editor (with all PaperCard instance in ItemPool), avoiding checking instance class improves performance a bit (saving a couple of hundreds of milliseconds). However, when this filter with also other inventory items (pack or deck), the same code as before is executed.
This commit is contained in:
@@ -137,13 +137,16 @@ public class ItemPool<T extends InventoryItem> implements Iterable<Entry<T, Inte
|
||||
return count;
|
||||
}
|
||||
|
||||
public final int countAll(Predicate<T> condition) {
|
||||
public final <U extends InventoryItem> int countAll(Predicate<U> condition){
|
||||
int count = 0;
|
||||
for (Entry<T, Integer> e : this) {
|
||||
if (condition.apply(e.getKey())) {
|
||||
count += e.getValue();
|
||||
Iterable<T> matchingKeys = Iterables.filter(this.items.keySet(), new Predicate<T>() {
|
||||
@Override
|
||||
public boolean apply(T item) {
|
||||
return condition.apply((U)item);
|
||||
}
|
||||
}
|
||||
});
|
||||
for (T key : matchingKeys)
|
||||
count += this.items.get(key);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,14 +75,23 @@ public abstract class StatTypeFilter<T extends InventoryItem> extends ToggleButt
|
||||
if (btnPackOrDeck != null) { //support special pack/deck case
|
||||
int count = items.countAll(ItemPredicate.Presets.IS_PACK_OR_DECK, InventoryItem.class);
|
||||
btnPackOrDeck.setText(String.valueOf(count));
|
||||
}
|
||||
|
||||
Iterator<StatTypes> buttonMapStatsIterator = buttonMap.keySet().iterator();
|
||||
while (buttonMapStatsIterator.hasNext()){
|
||||
StatTypes statTypes = buttonMapStatsIterator.next();
|
||||
if (statTypes.predicate != null){
|
||||
int count = items.countAll(Predicates.compose(statTypes.predicate, PaperCard.FN_GET_RULES), PaperCard.class);
|
||||
buttonMap.get(statTypes).setText(String.valueOf(count));
|
||||
Iterator<StatTypes> buttonMapStatsIterator = buttonMap.keySet().iterator();
|
||||
while (buttonMapStatsIterator.hasNext()){
|
||||
StatTypes statTypes = buttonMapStatsIterator.next();
|
||||
if (statTypes.predicate != null){
|
||||
count = items.countAll(Predicates.compose(statTypes.predicate, PaperCard.FN_GET_RULES), PaperCard.class);
|
||||
buttonMap.get(statTypes).setText(String.valueOf(count));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Iterator<StatTypes> buttonMapStatsIterator = buttonMap.keySet().iterator();
|
||||
while (buttonMapStatsIterator.hasNext()) {
|
||||
StatTypes statTypes = buttonMapStatsIterator.next();
|
||||
if (statTypes.predicate != null) {
|
||||
int count = items.countAll(Predicates.compose(statTypes.predicate, PaperCard.FN_GET_RULES));
|
||||
buttonMap.get(statTypes).setText(String.valueOf(count));
|
||||
}
|
||||
}
|
||||
}
|
||||
getWidget().revalidate();
|
||||
|
||||
Reference in New Issue
Block a user