Skip to content

Commit

Permalink
7903321: Use a set instead of a map to record methods in class 'Metho…
Browse files Browse the repository at this point in the history
…dGroup'

Reviewed-by: shade
  • Loading branch information
lgxbslgx authored and shipilev committed Sep 21, 2022
1 parent 8c7fedc commit 622ed6e
Showing 1 changed file with 10 additions and 13 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
Expand Down Expand Up @@ -35,15 +35,15 @@
class MethodGroup implements Comparable<MethodGroup> {
private final ClassInfo ci;
private final String name;
private final Map<MethodInvocation, MethodInvocation> methods;
private final Set<MethodInvocation> methods;
private final EnumSet<Mode> modes;
private final Map<String, String[]> params;
private boolean strictFP;

public MethodGroup(ClassInfo ci, String name) {
this.ci = ci;
this.name = name;
this.methods = new TreeMap<>();
this.methods = new TreeSet<>();
this.modes = EnumSet.noneOf(Mode.class);
this.params = new TreeMap<>();
}
Expand Down Expand Up @@ -72,20 +72,17 @@ public int compareTo(MethodGroup o) {

public void addMethod(MethodInfo method, int threads) {
MethodInvocation mi = new MethodInvocation(method, threads);
MethodInvocation exist = methods.get(mi);
if (exist == null) {
methods.put(mi, mi);
} else {
if (!methods.add(mi)) {
throw new GenerationException(
"@" + Benchmark.class.getSimpleName() + " method is duplicate with " +
exist.method.getQualifiedName() + ". JMH needs an uniquely named method, regardless of the arguments list. ",
"Duplicate @" + Benchmark.class.getSimpleName() + " method name: " +
mi.method.getQualifiedName() + ". JMH needs an uniquely named method, regardless of the arguments list. ",
method);
}
}

public Collection<MethodInfo> methods() {
Collection<MethodInfo> result = new ArrayList<>();
for (MethodInvocation m : methods.keySet()) {
for (MethodInvocation m : methods) {
result.add(m.method);
}
return result;
Expand Down Expand Up @@ -131,7 +128,7 @@ public Set<Mode> getModes() {
public int[] getGroupThreads() {
int[] threads = new int[methods.size()];
int c = 0;
for (MethodInvocation mi : methods.keySet()) {
for (MethodInvocation mi : methods) {
threads[c++] = mi.threads;
}
return threads;
Expand All @@ -140,7 +137,7 @@ public int[] getGroupThreads() {
public Optional<Collection<String>> getGroupLabels() {
if (methods.size() > 1) {
Collection<String> labels = new ArrayList<>();
for (MethodInvocation mi : methods.keySet()) {
for (MethodInvocation mi : methods) {
labels.add(mi.method.getName());
}
return Optional.eitherOf(labels);
Expand Down Expand Up @@ -283,7 +280,7 @@ public Optional<TimeValue> getTimeout() {

private <T extends Annotation> Collection<T> getAll(Class<T> annClass) {
Collection<T> results = new ArrayList<>();
for (MethodInvocation mi : methods.keySet()) {
for (MethodInvocation mi : methods) {
Collection<T> anns = BenchmarkGeneratorUtils.getAnnSuperAll(mi.method, ci, annClass);
if (!(results.isEmpty() || anns.isEmpty() || results.equals(anns))) {
throw new GenerationException("Colliding annotations: " + anns + " vs. " + results, mi.method);
Expand Down

0 comments on commit 622ed6e

Please sign in to comment.