While exploring Java EnumSet, i cam across two package-private class,
- RegularEnumSet
- JumboEnumSet
From EnumSet source :
if (universe.length <= 64)
return new RegularEnumSet<>(elementType, universe);
else
return new JumboEnumSet<>(elementType, universe);
Also RegularEnumSet Constructor look like :
RegularEnumSet(Class<E>elementType, Enum[] universe) {
super(elementType, universe);
}
whereas in case of JumboEnumSet constructor is :
JumboEnumSet(Class<E>elementType, Enum[] universe) {
super(elementType, universe);
elements = new long[(universe.length + 63) >>> 6];
}
So my doubts are :
Why it uses different EnumSet depending on size.How it impacts performance?
What is the logic behind JumboEnumSet of using elements array?