Skip to content

Commit 8b37ff8

Browse files
committed
Use Set.of() instead of Collections.emptySet() in core parts
Marko told me that it was actually faster to iterate and from what I can see it's true. I won't change it everywhere but it seems like a good idea to make the change in the Core parts. Note that some of the changes I made might not be critical but it wasn't worth the hassle to check everywhere if it actually made a noticeable difference given the size of the change.
1 parent fdbee13 commit 8b37ff8

File tree

8 files changed

+13
-17
lines changed

8 files changed

+13
-17
lines changed

core/deployment/src/main/java/io/quarkus/deployment/builditem/AdditionalIndexedClassesBuildItem.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.quarkus.deployment.builditem;
22

3-
import java.util.Collections;
43
import java.util.Set;
54

65
import io.quarkus.builder.item.MultiBuildItem;
@@ -18,7 +17,7 @@ public AdditionalIndexedClassesBuildItem(String... classesToIndex) {
1817
}
1918

2019
public AdditionalIndexedClassesBuildItem(String classToIndex) {
21-
this.classesToIndex = Collections.singleton(classToIndex);
20+
this.classesToIndex = Set.of(classToIndex);
2221
}
2322

2423
public Set<String> getClassesToIndex() {

core/deployment/src/main/java/io/quarkus/deployment/configuration/ConfigMappingUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static io.smallrye.config.ConfigMappings.ConfigClass.configClass;
44
import static org.jboss.jandex.AnnotationTarget.Kind.CLASS;
55

6-
import java.util.Collections;
76
import java.util.HashSet;
87
import java.util.List;
98
import java.util.Optional;
@@ -222,7 +221,7 @@ private static Set<Type> collectTypes(CombinedIndexBuildItem combinedIndex, Clas
222221
DotName configIfaceName = DotName.createSimple(configClass.getName());
223222
ClassInfo configIfaceInfo = index.getClassByName(configIfaceName);
224223
if ((configIfaceInfo == null) || configIfaceInfo.interfaceNames().isEmpty()) {
225-
return Collections.singleton(Type.create(configIfaceName, Type.Kind.CLASS));
224+
return Set.of(Type.create(configIfaceName, Type.Kind.CLASS));
226225
}
227226

228227
Set<DotName> allIfaces = new HashSet<>();

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -723,17 +723,17 @@ Collection<AnnotationInstance> extractInterceptorBindings(AnnotationInstance ann
723723
private static Collection<AnnotationInstance> extractAnnotations(AnnotationInstance annotation,
724724
Map<DotName, ClassInfo> singulars, Map<DotName, ClassInfo> repeatables) {
725725
if (!annotation.runtimeVisible()) {
726-
return Collections.emptyList();
726+
return List.of();
727727
}
728728
DotName annotationName = annotation.name();
729729
if (singulars.get(annotationName) != null) {
730-
return Collections.singleton(annotation);
730+
return Set.of(annotation);
731731
} else if (repeatables.get(annotationName) != null) {
732732
// repeatable, we need to extract actual annotations
733733
return Annotations.onlyRuntimeVisible(Arrays.asList(annotation.value().asNestedArray()));
734734
} else {
735735
// neither singular nor repeatable, return empty collection
736-
return Collections.emptyList();
736+
return List.of();
737737
}
738738
}
739739

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanResolverImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public Set<BeanInfo> resolveBeans(Type requiredType, Set<AnnotationInstance> req
4747
List<BeanInfo> beans = findMatching(typeAndQualifiers);
4848
Set<BeanInfo> ret;
4949
if (beans.isEmpty()) {
50-
ret = Collections.emptySet();
50+
ret = Set.of();
5151
} else if (beans.size() == 1) {
52-
ret = Collections.singleton(beans.get(0));
52+
ret = Set.of(beans.get(0));
5353
} else {
5454
ret = new HashSet<>(beans);
5555
}

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/InjectionPointInfo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.lang.reflect.Modifier;
66
import java.util.ArrayList;
77
import java.util.Collection;
8-
import java.util.Collections;
98
import java.util.HashSet;
109
import java.util.List;
1110
import java.util.ListIterator;
@@ -134,7 +133,7 @@ static InjectionPointInfo fromSyntheticInjectionPoint(TypeAndQualifiers typeAndQ
134133
InjectionPointInfo(Type requiredType, Set<AnnotationInstance> requiredQualifiers, InjectionPointKind kind,
135134
AnnotationTarget target, AnnotationTarget methodParameterTarget, boolean isTransientReference, boolean isDelegate) {
136135
this(new TypeAndQualifiers(requiredType, requiredQualifiers.isEmpty()
137-
? Collections.singleton(AnnotationInstance.create(DotNames.DEFAULT, null, Collections.emptyList()))
136+
? Set.of(AnnotationInstance.create(DotNames.DEFAULT, null, List.of()))
138137
: requiredQualifiers),
139138
kind, target, methodParameterTarget, isTransientReference, isDelegate);
140139
}

independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Interceptors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static InterceptorInfo createInterceptor(ClassInfo interceptorClass, BeanDeploym
7070
checkInterceptorFieldsAndMethods(interceptorClass, beanDeployment);
7171

7272
return new InterceptorInfo(interceptorClass, beanDeployment,
73-
bindings.size() == 1 ? Collections.singleton(bindings.iterator().next())
73+
bindings.size() == 1 ? Set.of(bindings.iterator().next())
7474
: Collections.unmodifiableSet(bindings),
7575
Injection.forBean(interceptorClass, null, beanDeployment, transformer, Injection.BeanType.INTERCEPTOR),
7676
priority);

independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/ContextDataMap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Set<Map.Entry<String, Object>> entrySet() {
8282
final AbstractMap.SimpleImmutableEntry<String, Object> firstEntry = new AbstractMap.SimpleImmutableEntry<>(
8383
ArcInvocationContext.KEY_INTERCEPTOR_BINDINGS, interceptorBindings);
8484
if (delegate == null) {
85-
return Collections.singleton(firstEntry);
85+
return Set.of(firstEntry);
8686
} else {
8787
Set<Map.Entry<String, Object>> entries = new HashSet<>(delegate.size() + 1);
8888
entries.addAll(delegate.entrySet());
@@ -107,7 +107,7 @@ public boolean isEmpty() {
107107
@Override
108108
public Set<String> keySet() {
109109
if (delegate == null) {
110-
return Collections.singleton(ArcInvocationContext.KEY_INTERCEPTOR_BINDINGS);
110+
return Set.of(ArcInvocationContext.KEY_INTERCEPTOR_BINDINGS);
111111
} else {
112112
Set<String> set = new HashSet<>(delegate.size() + 1);
113113
set.addAll(delegate.keySet());
@@ -145,7 +145,7 @@ public int size() {
145145
@Override
146146
public Collection<Object> values() {
147147
if (delegate == null) {
148-
return Collections.singleton(interceptorBindings);
148+
return Set.of(interceptorBindings);
149149
} else {
150150
List<Object> list = new ArrayList<>(delegate.size() + 1);
151151
list.addAll(delegate.values());

independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/Qualifiers.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.lang.reflect.Method;
77
import java.util.Arrays;
88
import java.util.Collection;
9-
import java.util.Collections;
109
import java.util.HashMap;
1110
import java.util.Map;
1211
import java.util.Set;
@@ -20,7 +19,7 @@ public final class Qualifiers {
2019

2120
public static final Set<Annotation> DEFAULT_QUALIFIERS = Set.of(Default.Literal.INSTANCE, Any.Literal.INSTANCE);
2221

23-
public static final Set<Annotation> IP_DEFAULT_QUALIFIERS = Collections.singleton(Default.Literal.INSTANCE);
22+
public static final Set<Annotation> IP_DEFAULT_QUALIFIERS = Set.of(Default.Literal.INSTANCE);
2423

2524
final Set<String> allQualifiers;
2625
// custom qualifier -> non-binding members (can be empty but never null)

0 commit comments

Comments
 (0)