EnumSet.allOf can take advantage of the bulk BitSet.set(start, end) operation to run faster instead of adding each element individually.

This commit is contained in:
Mike Keesey 2012-07-06 23:47:42 -06:00
parent 39ad6da290
commit ba1719f1ef

View File

@ -53,7 +53,7 @@ public class EnumSet<T extends Enum<T>> extends AbstractSet<T> {
public static <T extends Enum<T>>EnumSet<T> allOf(Class<T> elementType) {
EnumSet<T> enumSet = createEmptyEnumSet(elementType);
addAllElementsToSet(Arrays.asList(elementType.getEnumConstants()), enumSet);
enumSet.bitset.set(0, elementType.getEnumConstants().length);
return enumSet;
}