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

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022, 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
@ -498,12 +498,11 @@ final class Resolver {
*/
private Map<ResolvedModule, Set<ResolvedModule>> makeGraph(Configuration cf) {
// initial capacity of maps to avoid resizing
int capacity = 1 + (4 * nameToReference.size())/ 3;
int moduleCount = nameToReference.size();
// the "reads" graph starts as a module dependence graph and
// is iteratively updated to be the readability graph
Map<ResolvedModule, Set<ResolvedModule>> g1 = new HashMap<>(capacity);
Map<ResolvedModule, Set<ResolvedModule>> g1 = HashMap.newHashMap(moduleCount);
// the "requires transitive" graph, contains requires transitive edges only
Map<ResolvedModule, Set<ResolvedModule>> g2;
@ -512,7 +511,7 @@ final class Resolver {
// as there may be selected modules that have a dependency on modules in
// the parent configuration.
if (ModuleLayer.boot() == null) {
g2 = new HashMap<>(capacity);
g2 = HashMap.newHashMap(moduleCount);
} else {
g2 = parents.stream()
.flatMap(Configuration::configurations)
@ -539,7 +538,7 @@ final class Resolver {
// populate g1 and g2 with the dependences from the selected modules
Map<String, ResolvedModule> nameToResolved = new HashMap<>(capacity);
Map<String, ResolvedModule> nameToResolved = HashMap.newHashMap(moduleCount);
for (ModuleReference mref : nameToReference.values()) {
ModuleDescriptor descriptor = mref.descriptor();