Skip to content

Commit

Permalink
Don't make HashMaps with tiny capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
mernst authored Dec 17, 2024
1 parent 2a05396 commit 77b5f74
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public LombokSupport(CalledMethodsAnnotatedTypeFactory atypeFactory) {
* available and that method returns null). See the code in {@link
* #getLombokRequiredProperties(Element)} that handles fields.
*/
private final Map<Element, Name> defaultedElements = new HashMap<>(2);
private final Map<Element, Name> defaultedElements = new HashMap<>(4);

@Override
public boolean isBuilderBuildMethod(ExecutableElement candidateBuildElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ public CFGTranslationPhaseOne(
exceptionalExitLabel = new Label();
tryStack = new TryStack(exceptionalExitLabel);
returnTargetLC = new LabelCell(regularExitLabel);
breakLabels = new HashMap<>(2);
continueLabels = new HashMap<>(2);
breakLabels = new HashMap<>(4);
continueLabels = new HashMap<>(4);
returnNodes = new ArrayList<>();
declaredClasses = new ArrayList<>();
declaredLambdas = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Map<String, Object> visualize(
ControlFlowGraph cfg, Block entry, @Nullable Analysis<V, S, T> analysis) {
String dotGraph = visualizeGraph(cfg, entry, analysis);

Map<String, Object> vis = new HashMap<>(2);
Map<String, Object> vis = new HashMap<>(4);
vis.put("dotGraph", dotGraph);
return vis;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ private static class ClassOrInterfaceAnnos implements DeepCopyable<ClassOrInterf
public Map<String, CallableDeclarationAnnos> callableDeclarations = new HashMap<>();

/** Mapping from field names to wrappers for those fields. */
public Map<String, FieldAnnos> fields = new HashMap<>(2);
public Map<String, FieldAnnos> fields = new HashMap<>(4);

/** Collection of declared enum constants (empty if not an enum). */
public Set<String> enumConstants = new HashSet<>(2);
Expand Down Expand Up @@ -1718,9 +1718,8 @@ public boolean addDeclarationAnnotation(AnnotationMirror annotation) {
public Map<String, InferredDeclared> getPreconditions() {
if (preconditions == null) {
return Collections.emptyMap();
} else {
return Collections.unmodifiableMap(preconditions);
}
return Collections.unmodifiableMap(preconditions);
}

/**
Expand Down Expand Up @@ -1765,7 +1764,7 @@ public AnnotatedTypeMirror getPreconditionsForExpression(
AnnotatedTypeMirror declaredType,
AnnotatedTypeFactory atf) {
if (preconditions == null) {
preconditions = new HashMap<>(1);
preconditions = new HashMap<>(4);
}

if (!preconditions.containsKey(expression)) {
Expand Down Expand Up @@ -1798,7 +1797,7 @@ public AnnotatedTypeMirror getPostconditionsForExpression(
AnnotatedTypeMirror declaredType,
AnnotatedTypeFactory atf) {
if (postconditions == null) {
postconditions = new HashMap<>(1);
postconditions = new HashMap<>(4);
}

if (!postconditions.containsKey(expression)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ public static class AnnotationFileAnnotations {
* than in the real files. So, map keys are the verbose element name, as returned by
* ElementUtils.getQualifiedName.
*/
public final Map<String, AnnotationMirrorSet> declAnnos = new HashMap<>(1);
public final Map<String, AnnotationMirrorSet> declAnnos = new HashMap<>(4);

/**
* Map from a method element to all the fake overrides of it. Given a key {@code ee}, the fake
* overrides are always in subtypes of {@code ee.getEnclosingElement()}, which is the same as
* {@code ee.getReceiverType()}.
*/
public final Map<ExecutableElement, List<IPair<TypeMirror, AnnotatedTypeMirror>>>
fakeOverrides = new HashMap<>(1);
fakeOverrides = new HashMap<>(4);

/** Maps fully qualified record name to information in the stub file. */
public final Map<String, RecordStub> records = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ public AnnotatedTypeVariable asUse() {

AnnotatedTypeVariable result = this.shallowCopy();
result.declaration = false;
Map<TypeVariable, AnnotatedTypeMirror> mapping = new HashMap<>(1);
Map<TypeVariable, AnnotatedTypeMirror> mapping = new HashMap<>(4);
mapping.put(getUnderlyingType(), result);
AnnotatedTypeMirror upperBound =
atypeFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2304,7 +2304,7 @@ public boolean getShouldDefaultTypeVarLocals() {
}
boolean verbose = checker.hasOption("verbosecfg");

Map<String, Object> args = new HashMap<>(2);
Map<String, Object> args = new HashMap<>(4);
args.put("outdir", flowdotdir);
args.put("verbose", verbose);
args.put("checkerName", getCheckerName());
Expand Down

0 comments on commit 77b5f74

Please sign in to comment.