Skip to content

Commit 0e32c0a

Browse files
committed
Fix speed regression in property binding
Update `MapBinder` to only compute values if an entry does not already exist. Prior to this commit, a binding to `Map<String,List<String>>` would be expensive since the same entries would be bound many times. For example, given: foo.bar[0]=baz1 foo.bar[1]=baz1 foo.bar[2]=baz1 The Map binder would iterate over the properties `bar[0]`, `bar[1]` and `bar[2]`. Each of these properties resulted in the same actual key of `bar` which would then be bound to list multiple times. Fixes gh-10093
1 parent 402dcb7 commit 0e32c0a

File tree

1 file changed

+2
-2
lines changed
  • spring-boot/src/main/java/org/springframework/boot/context/properties/bind

1 file changed

+2
-2
lines changed

spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ public void bindEntries(ConfigurationPropertySource source,
103103
ConfigurationPropertyName entryName = getEntryName(source, name);
104104
Object key = getContext().getConversionService()
105105
.convert(getKeyName(entryName), this.keyType);
106-
Object value = this.elementBinder.bind(entryName, valueBindable);
107-
map.putIfAbsent(key, value);
106+
map.computeIfAbsent(key,
107+
(k) -> this.elementBinder.bind(entryName, valueBindable));
108108
}
109109
}
110110
}

0 commit comments

Comments
 (0)