mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8186958: Need method to create pre-sized HashMap
Reviewed-by: chegar, naoto, joehw, lancea, wetmore, smarks
This commit is contained in:
parent
41fc078323
commit
87faa85c59
30 changed files with 208 additions and 73 deletions
|
@ -744,8 +744,7 @@ class Character implements java.io.Serializable, Comparable<Character>, Constabl
|
|||
* 0.75 - the default load factor of HashMap
|
||||
*/
|
||||
private static final int NUM_ENTITIES = 737;
|
||||
private static Map<String, UnicodeBlock> map =
|
||||
new HashMap<>((int)(NUM_ENTITIES / 0.75f + 1.0f));
|
||||
private static Map<String, UnicodeBlock> map = HashMap.newHashMap(NUM_ENTITIES);
|
||||
|
||||
/**
|
||||
* Creates a UnicodeBlock with the given identifier name.
|
||||
|
@ -8572,7 +8571,7 @@ class Character implements java.io.Serializable, Comparable<Character>, Constabl
|
|||
|
||||
private static final HashMap<String, Character.UnicodeScript> aliases;
|
||||
static {
|
||||
aliases = new HashMap<>((int)(162 / 0.75f + 1.0f));
|
||||
aliases = HashMap.newHashMap(162);
|
||||
aliases.put("ADLM", ADLAM);
|
||||
aliases.put("AGHB", CAUCASIAN_ALBANIAN);
|
||||
aliases.put("AHOM", AHOM);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 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
|
||||
|
@ -980,7 +980,7 @@ public final class Module implements AnnotatedElement {
|
|||
// the packages to all unnamed modules.
|
||||
Map<String, Set<Module>> openPackages = this.openPackages;
|
||||
if (openPackages == null) {
|
||||
openPackages = new HashMap<>((4 * (concealedPkgs.size() + exportedPkgs.size()) / 3) + 1);
|
||||
openPackages = HashMap.newHashMap(concealedPkgs.size() + exportedPkgs.size());
|
||||
} else {
|
||||
openPackages = new HashMap<>(openPackages);
|
||||
}
|
||||
|
@ -1133,8 +1133,7 @@ public final class Module implements AnnotatedElement {
|
|||
boolean isBootLayer = (ModuleLayer.boot() == null);
|
||||
|
||||
int numModules = cf.modules().size();
|
||||
int cap = (int)(numModules / 0.75f + 1.0f);
|
||||
Map<String, Module> nameToModule = new HashMap<>(cap);
|
||||
Map<String, Module> nameToModule = HashMap.newHashMap(numModules);
|
||||
|
||||
// to avoid repeated lookups and reduce iteration overhead, we create
|
||||
// arrays holding correlated information about each module.
|
||||
|
|
|
@ -1655,7 +1655,7 @@ public class Thread implements Runnable {
|
|||
// Get a snapshot of the list of all threads
|
||||
Thread[] threads = getThreads();
|
||||
StackTraceElement[][] traces = dumpThreads(threads);
|
||||
Map<Thread, StackTraceElement[]> m = new HashMap<>(threads.length);
|
||||
Map<Thread, StackTraceElement[]> m = HashMap.newHashMap(threads.length);
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
StackTraceElement[] stackTrace = traces[i];
|
||||
if (stackTrace != null) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 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
|
||||
|
@ -290,7 +290,7 @@ abstract class MethodHandleImpl {
|
|||
BoundMethodHandle mh = target.rebind();
|
||||
|
||||
// Match each unique conversion to the positions at which it is to be applied
|
||||
var convSpecMap = new HashMap<Object, int[]>(((4 * convCount) / 3) + 1);
|
||||
HashMap<Object, int[]> convSpecMap = HashMap.newHashMap(convCount);
|
||||
for (int i = 0; i < convSpecs.length - MH_RECEIVER_OFFSET; i++) {
|
||||
Object convSpec = convSpecs[i];
|
||||
if (convSpec == null) continue;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue