From 700e89097ce1a553835b58e09b362d94b30a2a33 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Fri, 12 May 2023 11:57:33 +0200 Subject: [PATCH] Polish See https://stackoverflow.com/questions/28671903/the-hashsett-removeall-method-is-surprisingly-slow --- .../classpath/CheckClasspathForUnnecessaryExclusions.java | 6 ++---- .../autoconfigure/condition/ConditionEvaluationReport.java | 4 ++-- .../boot/web/error/ErrorAttributeOptions.java | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/classpath/CheckClasspathForUnnecessaryExclusions.java b/buildSrc/src/main/java/org/springframework/boot/build/classpath/CheckClasspathForUnnecessaryExclusions.java index 6ea9aa3dc9..13b50991a5 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/classpath/CheckClasspathForUnnecessaryExclusions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/classpath/CheckClasspathForUnnecessaryExclusions.java @@ -18,7 +18,6 @@ package org.springframework.boot.build.classpath; import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -107,14 +106,13 @@ public class CheckClasspathForUnnecessaryExclusions extends DefaultTask { this.exclusionsByDependencyId.forEach((dependencyId, exclusions) -> { if (!exclusions.isEmpty()) { Dependency toCheck = this.dependencyById.get(dependencyId); - List dependencies = this.configurations.detachedConfiguration(toCheck, this.platform) + this.configurations.detachedConfiguration(toCheck, this.platform) .getIncoming() .getArtifacts() .getArtifacts() .stream() .map(this::getId) - .collect(Collectors.toList()); - exclusions.removeAll(dependencies); + .forEach(exclusions::remove); removeProfileExclusions(dependencyId, exclusions); if (!exclusions.isEmpty()) { unnecessaryExclusions.put(dependencyId, exclusions); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java index 4a945908f2..cb987b1af3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReport.java @@ -147,7 +147,7 @@ public final class ConditionEvaluationReport { */ public Set getUnconditionalClasses() { Set filtered = new HashSet<>(this.unconditionalClasses); - filtered.removeAll(this.exclusions); + this.exclusions.forEach(filtered::remove); return Collections.unmodifiableSet(filtered); } @@ -166,7 +166,7 @@ public final class ConditionEvaluationReport { * @return the {@link ConditionEvaluationReport} or {@code null} */ public static ConditionEvaluationReport find(BeanFactory beanFactory) { - if (beanFactory != null && beanFactory instanceof ConfigurableListableBeanFactory) { + if (beanFactory instanceof ConfigurableListableBeanFactory) { return ConditionEvaluationReport.get((ConfigurableListableBeanFactory) beanFactory); } return null; diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/error/ErrorAttributeOptions.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/error/ErrorAttributeOptions.java index 707a889be1..ecf1ddc862 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/error/ErrorAttributeOptions.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/error/ErrorAttributeOptions.java @@ -75,7 +75,7 @@ public final class ErrorAttributeOptions { */ public ErrorAttributeOptions excluding(Include... excludes) { EnumSet updated = copyIncludes(); - updated.removeAll(Arrays.asList(excludes)); + Arrays.stream(excludes).forEach(updated::remove); return new ErrorAttributeOptions(Collections.unmodifiableSet(updated)); }