8200696: Optimal initial capacity of java.lang.Class.enumConstantDirectory

Reviewed-by: dholmes, redestad
This commit is contained in:
Ivan Gerasimov 2018-04-04 14:09:31 -07:00
parent ceea439679
commit 277ac7e034
3 changed files with 141 additions and 4 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -3529,7 +3529,7 @@ public final class Class<T> implements java.io.Serializable,
if (universe == null)
throw new IllegalArgumentException(
getName() + " is not an enum type");
directory = new HashMap<>(2 * universe.length);
directory = new HashMap<>((int)(universe.length / 0.75f) + 1);
for (T constant : universe) {
directory.put(((Enum<?>)constant).name(), constant);
}