Skip to content

Commit 5b3e1aa

Browse files
dreis2211wilkinsona
authored andcommitted
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
1 parent 7ed92e9 commit 5b3e1aa

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public boolean isAncestorOf(ConfigurationPropertyName name) {
237237
if (this.getNumberOfElements() >= name.getNumberOfElements()) {
238238
return false;
239239
}
240-
for (int i = 0; i < this.elements.getSize(); i++) {
240+
for (int i = this.elements.getSize() - 1; i >= 0; i--) {
241241
if (!elementEquals(this.elements, name.elements, i)) {
242242
return false;
243243
}
@@ -309,7 +309,7 @@ public boolean equals(Object obj) {
309309
&& other.elements.canShortcutWithSource(ElementType.UNIFORM)) {
310310
return toString().equals(other.toString());
311311
}
312-
for (int i = 0; i < this.elements.getSize(); i++) {
312+
for (int i = this.elements.getSize() - 1; i >= 0; i--) {
313313
if (!elementEquals(this.elements, other.elements, i)) {
314314
return false;
315315
}

0 commit comments

Comments
 (0)