Lets not do hundreds of object clones when they are nearly never needed.

This commit is contained in:
t00thpick1 2014-12-30 00:31:36 -05:00
parent 190c2d793f
commit 3f949e18cc

View File

@ -16,7 +16,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class CmdShow extends FCommand { public class CmdShow extends FCommand {
private static final int ARBITRARY_LIMIT = 25000;
public CmdShow() { public CmdShow() {
this.aliases.add("show"); this.aliases.add("show");
this.aliases.add("who"); this.aliases.add("who");
@ -70,11 +70,6 @@ public class CmdShow extends FCommand {
Relation rel = otherFaction.getRelationTo(faction); Relation rel = otherFaction.getRelationTo(faction);
String s = otherFaction.getTag(fme); String s = otherFaction.getTag(fme);
if (rel.isAlly()) { if (rel.isAlly()) {
FancyMessage beforeAdd = null;
try {
beforeAdd = currentAllies.clone();
} catch (CloneNotSupportedException ignored) {}
if (firstAlly) { if (firstAlly) {
currentAllies.then(s).tooltip(getToolTips(otherFaction)); currentAllies.then(s).tooltip(getToolTips(otherFaction));
} else { } else {
@ -82,16 +77,11 @@ public class CmdShow extends FCommand {
} }
firstAlly = false; firstAlly = false;
if (currentAllies.toJSONString().length() > Short.MAX_VALUE) { if (currentAllies.toJSONString().length() > ARBITRARY_LIMIT) {
allies.add(beforeAdd); allies.add(currentAllies);
currentAllies = new FancyMessage(s).tooltip(getToolTips(otherFaction)); currentAllies = new FancyMessage();
} }
} else if (rel.isEnemy()) { } else if (rel.isEnemy()) {
FancyMessage beforeAdd = null;
try {
beforeAdd = currentEnemies.clone();
} catch (CloneNotSupportedException ignored) {}
if (firstEnemy) { if (firstEnemy) {
currentEnemies.then(s).tooltip(getToolTips(otherFaction)); currentEnemies.then(s).tooltip(getToolTips(otherFaction));
} else { } else {
@ -99,9 +89,9 @@ public class CmdShow extends FCommand {
} }
firstEnemy = false; firstEnemy = false;
if (currentEnemies.toJSONString().length() > Short.MAX_VALUE) { if (currentEnemies.toJSONString().length() > ARBITRARY_LIMIT) {
enemies.add(beforeAdd); enemies.add(currentEnemies);
currentEnemies = new FancyMessage(s).tooltip(getToolTips(otherFaction)); currentEnemies = new FancyMessage();
} }
} }
} }
@ -117,11 +107,6 @@ public class CmdShow extends FCommand {
for (FPlayer p : MiscUtil.rankOrder(faction.getFPlayers())) { for (FPlayer p : MiscUtil.rankOrder(faction.getFPlayers())) {
String name = p.getNameAndTitle(); String name = p.getNameAndTitle();
if (p.isOnline()) { if (p.isOnline()) {
FancyMessage beforeAdd = null;
try {
beforeAdd = currentOnline.clone();
} catch (CloneNotSupportedException ignored) {}
if (firstOnline) { if (firstOnline) {
currentOnline.then(name).tooltip(getToolTips(p)); currentOnline.then(name).tooltip(getToolTips(p));
} else { } else {
@ -129,16 +114,11 @@ public class CmdShow extends FCommand {
} }
firstOnline = false; firstOnline = false;
if (currentOnline.toJSONString().length() > Short.MAX_VALUE) { if (currentOnline.toJSONString().length() > ARBITRARY_LIMIT) {
online.add(beforeAdd); online.add(currentOnline);
currentOnline = new FancyMessage(name).tooltip(getToolTips(p)); currentOnline = new FancyMessage();
} }
} else { } else {
FancyMessage beforeAdd = null;
try {
beforeAdd = currentOffline.clone();
} catch (CloneNotSupportedException ignored) {}
if (firstOffline) { if (firstOffline) {
currentOffline.then(name).tooltip(getToolTips(p)); currentOffline.then(name).tooltip(getToolTips(p));
} else { } else {
@ -146,9 +126,9 @@ public class CmdShow extends FCommand {
} }
firstOffline = false; firstOffline = false;
if (currentOffline.toJSONString().length() > Short.MAX_VALUE) { if (currentOffline.toJSONString().length() > ARBITRARY_LIMIT) {
offline.add(beforeAdd); offline.add(currentOffline);
currentOffline = new FancyMessage(name).tooltip(getToolTips(p)); currentOffline = new FancyMessage();
} }
} }
} }