ThreadLocalStringBuilder is slower here

by about 30%, as measured by JMH

avoiding garbage is more important when the string is more than 5
characters long
This commit is contained in:
Neil Gentleman 2016-10-15 22:22:13 -07:00
parent f438b76b31
commit 8109532adf

View file

@ -31,12 +31,9 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import mage.util.Copyable;
import mage.util.ThreadLocalStringBuilder;
public class ObjectColor implements Serializable, Copyable<ObjectColor>, Comparable<ObjectColor> {
private static final ThreadLocalStringBuilder threadLocalBuilder = new ThreadLocalStringBuilder(10);
public static final ObjectColor WHITE = new ObjectColor("W");
public static final ObjectColor BLUE = new ObjectColor("U");
public static final ObjectColor BLACK = new ObjectColor("B");
@ -231,7 +228,7 @@ public class ObjectColor implements Serializable, Copyable<ObjectColor>, Compara
@Override
public String toString() {
StringBuilder sb = threadLocalBuilder.get();
StringBuilder sb = new StringBuilder(5);
if (white) {
sb.append("W");
}