From 81dee5413723796308372d073de6e76d90ee0a40 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sat, 22 Mar 2025 16:20:16 -0700 Subject: [PATCH] Improve ConfigurationPropertyName equals/hashCode performance Update `ConfigurationPropertyName` to improve performance of the `equals(...)` and `hashCode()` methods by making the following changes: - Move element hashCode logic to Element and cache the results - Exit the equals method early if hashcodes don't match - Exit the equals method early if toString() values match Closes gh-44857 --- .../source/ConfigurationPropertyName.java | 70 +++++++++++++------ 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java index a744ec9066..584fa8c188 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java @@ -291,7 +291,7 @@ public final class ConfigurationPropertyName implements Comparable= name.getNumberOfElements()) { return false; } - return elementsEqual(name); + return endsWithElementsEqualTo(name); } @Override @@ -357,10 +357,20 @@ public final class ConfigurationPropertyName implements Comparable= 0; i--) { if (elementDiffers(this.elements, name.elements, i)) { return false; @@ -508,19 +518,7 @@ public final class ConfigurationPropertyName implements Comparable