Skip to content

Commit 097ab91

Browse files
committed
Merge pull request #13473 from izeye:empty-list
* pr/13473: Reduce object creation in findMatchingItemMetadata()
2 parents 27bb461 + f34fb5f commit 097ab91

File tree

1 file changed

+3
-7
lines changed
  • spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata

1 file changed

+3
-7
lines changed

spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,11 @@ private <K, V> void add(Map<K, List<V>> map, K key, V value) {
145145
}
146146

147147
private ItemMetadata findMatchingItemMetadata(ItemMetadata metadata) {
148-
List<ItemMetadata> candidates = getCandidates(metadata.getName());
149-
if (candidates.isEmpty()) {
148+
List<ItemMetadata> candidates = this.items.get(metadata.getName());
149+
if (candidates == null || candidates.isEmpty()) {
150150
return null;
151151
}
152+
candidates = new ArrayList<>(candidates);
152153
candidates.removeIf((itemMetadata) -> !itemMetadata.hasSameType(metadata));
153154
if (candidates.size() > 1 && metadata.getType() != null) {
154155
candidates.removeIf(
@@ -165,11 +166,6 @@ private ItemMetadata findMatchingItemMetadata(ItemMetadata metadata) {
165166
return null;
166167
}
167168

168-
private List<ItemMetadata> getCandidates(String name) {
169-
List<ItemMetadata> candidates = this.items.get(name);
170-
return (candidates != null ? new ArrayList<>(candidates) : new ArrayList<>());
171-
}
172-
173169
private boolean nullSafeEquals(Object o1, Object o2) {
174170
if (o1 == o2) {
175171
return true;

0 commit comments

Comments
 (0)