perf[set]: use Boolean instead Object constant

This commit is contained in:
godotg committed 2022-10-07 22:43:38 +08:00
1 parent 5f6263e380
commit faea293e20
5 files changed
+15 -17

No files matched your search

@@ -34,8 +34,6 @@ public abstract class ArrayUtils {
public static final double[] EMPTY_DOUBLE_ARRAY = new double[0]; public static final double[] EMPTY_DOUBLE_ARRAY = new double[0];
public static final char[] EMPTY_CHAR_ARRAY = new char[0]; public static final char[] EMPTY_CHAR_ARRAY = new char[0];
public static final Object EMPTY_OBJECT = new Object();
/** /**
* unbox * unbox
*/ */
@@ -24,7 +24,7 @@ import java.util.Objects;
*/ */
public class HashSetByte extends AbstractSet<Byte> { public class HashSetByte extends AbstractSet<Byte> {
private final ByteObjectHashMap<Object> map; private final ByteObjectHashMap<Boolean> map;
public HashSetByte() { public HashSetByte() {
map = new ByteObjectHashMap<>(); map = new ByteObjectHashMap<>();
@@ -56,16 +56,16 @@ public class HashSetByte extends AbstractSet<Byte> {
@Override @Override
public boolean add(Byte e) { public boolean add(Byte e) {
return map.put(e, ArrayUtils.EMPTY_OBJECT) == null; return map.put(e, Boolean.TRUE) == null;
} }
public boolean add(byte e) { public boolean add(byte e) {
return map.put(e, ArrayUtils.EMPTY_OBJECT) == null; return map.put(e, Boolean.TRUE) == null;
} }
@Override @Override
public boolean remove(Object o) { public boolean remove(Object o) {
return map.remove(o) == ArrayUtils.EMPTY_OBJECT; return map.remove(o) != null;
} }
@Override @Override
@@ -24,7 +24,7 @@ import java.util.Objects;
*/ */
public class HashSetInt extends AbstractSet<Integer> { public class HashSetInt extends AbstractSet<Integer> {
private final IntObjectHashMap<Object> map; private final IntObjectHashMap<Boolean> map;
public HashSetInt() { public HashSetInt() {
map = new IntObjectHashMap<>(); map = new IntObjectHashMap<>();
@@ -56,16 +56,16 @@ public class HashSetInt extends AbstractSet<Integer> {
@Override @Override
public boolean add(Integer e) { public boolean add(Integer e) {
return map.put(e, ArrayUtils.EMPTY_OBJECT) == null; return map.put(e, Boolean.TRUE) == null;
} }
public boolean add(int e) { public boolean add(int e) {
return map.put(e, ArrayUtils.EMPTY_OBJECT) == null; return map.put(e, Boolean.TRUE) == null;
} }
@Override @Override
public boolean remove(Object o) { public boolean remove(Object o) {
return map.remove(o) == ArrayUtils.EMPTY_OBJECT; return map.remove(o) != null;
} }
@Override @Override
@@ -56,16 +56,16 @@ public class HashSetLong extends AbstractSet<Long> {
@Override @Override
public boolean add(Long e) { public boolean add(Long e) {
return map.put(e, ArrayUtils.EMPTY_OBJECT) == null; return map.put(e, Boolean.TRUE) == null;
} }
public boolean add(long e) { public boolean add(long e) {
return map.put(e, ArrayUtils.EMPTY_OBJECT) == null; return map.put(e, Boolean.TRUE) == null;
} }
@Override @Override
public boolean remove(Object o) { public boolean remove(Object o) {
return map.remove(o) == ArrayUtils.EMPTY_OBJECT; return map.remove(o) != null;
} }
@Override @Override
@@ -24,7 +24,7 @@ import java.util.Objects;
*/ */
public class HashSetShort extends AbstractSet<Short> { public class HashSetShort extends AbstractSet<Short> {
private final ShortObjectHashMap<Object> map; private final ShortObjectHashMap<Boolean> map;
public HashSetShort() { public HashSetShort() {
map = new ShortObjectHashMap<>(); map = new ShortObjectHashMap<>();
@@ -56,16 +56,16 @@ public class HashSetShort extends AbstractSet<Short> {
@Override @Override
public boolean add(Short e) { public boolean add(Short e) {
return map.put(e, ArrayUtils.EMPTY_OBJECT) == null; return map.put(e, Boolean.TRUE) == null;
} }
public boolean add(short e) { public boolean add(short e) {
return map.put(e, ArrayUtils.EMPTY_OBJECT) == null; return map.put(e, Boolean.TRUE) == null;
} }
@Override @Override
public boolean remove(Object o) { public boolean remove(Object o) {
return map.remove(o) == ArrayUtils.EMPTY_OBJECT; return map.remove(o) != null;
} }
@Override @Override