From 5b3e1aa21a7075989538484c1a9c35eff102ab4a Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Thu, 24 Jan 2019 21:25:37 +0100 Subject: [PATCH] Optimize ConfigurationPropertyName This commit changes the iteration order when checking for element equality. This is based on the educated guess that child elements will likely differ while parents will probably be the same. E.g. comparing "spring.banner.charset" with "spring.banner.location" will now first check "charset" against "location" and thus saves some cycles for elements that will be the same. See gh-15782 --- .../context/properties/source/ConfigurationPropertyName.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 ad3e5b3350..17069ecbf3 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 @@ -237,7 +237,7 @@ public final class ConfigurationPropertyName if (this.getNumberOfElements() >= name.getNumberOfElements()) { return false; } - for (int i = 0; i < this.elements.getSize(); i++) { + for (int i = this.elements.getSize() - 1; i >= 0; i--) { if (!elementEquals(this.elements, name.elements, i)) { return false; } @@ -309,7 +309,7 @@ public final class ConfigurationPropertyName && other.elements.canShortcutWithSource(ElementType.UNIFORM)) { return toString().equals(other.toString()); } - for (int i = 0; i < this.elements.getSize(); i++) { + for (int i = this.elements.getSize() - 1; i >= 0; i--) { if (!elementEquals(this.elements, other.elements, i)) { return false; }