8186958: Need method to create pre-sized HashMap

Reviewed-by: chegar, naoto, joehw, lancea, wetmore, smarks
This commit is contained in:
XenoAmess 2022-04-19 00:03:56 +00:00 committed by Stuart Marks
parent 41fc078323
commit 87faa85c59
30 changed files with 208 additions and 73 deletions

View file

@ -3910,7 +3910,7 @@ public final class Class<T> implements java.io.Serializable,
if (universe == null)
throw new IllegalArgumentException(
getName() + " is not an enum class");
directory = new HashMap<>((int)(universe.length / 0.75f) + 1);
directory = HashMap.newHashMap(universe.length);
for (T constant : universe) {
directory.put(((Enum<?>)constant).name(), constant);
}
@ -4125,10 +4125,10 @@ public final class Class<T> implements java.io.Serializable,
Class<? extends Annotation> annotationClass = e.getKey();
if (AnnotationType.getInstance(annotationClass).isInherited()) {
if (annotations == null) { // lazy construction
annotations = new LinkedHashMap<>((Math.max(
annotations = LinkedHashMap.newLinkedHashMap(Math.max(
declaredAnnotations.size(),
Math.min(12, declaredAnnotations.size() + superAnnotations.size())
) * 4 + 2) / 3
)
);
}
annotations.put(annotationClass, e.getValue());