8221921: Implement size() / isEmpty() in immutable collections

Reviewed-by: smarks
This commit is contained in:
Claes Redestad 2019-04-04 23:21:52 +02:00
parent 15d989faa4
commit f7fa05ca72

View file

@ -403,6 +403,11 @@ class ImmutableCollections {
return e1 != null ? 2 : 1;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public E get(int index) {
if (index == 0) {
@ -480,7 +485,7 @@ class ImmutableCollections {
@Override
public boolean isEmpty() {
return size() == 0;
return elements.length == 0;
}
@Override
@ -578,6 +583,11 @@ class ImmutableCollections {
return (e1 == null) ? 1 : 2;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean contains(Object o) {
return o.equals(e0) || o.equals(e1); // implicit nullcheck of o
@ -705,6 +715,11 @@ class ImmutableCollections {
return size;
}
@Override
public boolean isEmpty() {
return size == 0;
}
@Override
public boolean contains(Object o) {
Objects.requireNonNull(o);
@ -876,6 +891,16 @@ class ImmutableCollections {
return o.equals(v0); // implicit nullcheck of o
}
@Override
public int size() {
return 1;
}
@Override
public boolean isEmpty() {
return false;
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
throw new InvalidObjectException("not serial proxy");
}
@ -993,6 +1018,11 @@ class ImmutableCollections {
return size;
}
@Override
public boolean isEmpty() {
return size == 0;
}
class MapNIterator implements Iterator<Map.Entry<K,V>> {
private int remaining;