Skip to content

Commit 2ab2844

Browse files
committed
Merge pull request #20755 from dreis2211
* pr/20755: Improve Binder performance slightly Closes gh-20755
2 parents 0611b6d + 43936d6 commit 2ab2844

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -367,7 +367,7 @@ private <T> T handleBindError(ConfigurationPropertyName name, Bindable<T> target
367367
private <T> Object bindObject(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler,
368368
Context context, boolean allowRecursiveBinding) {
369369
ConfigurationProperty property = findProperty(name, context);
370-
if (property == null && containsNoDescendantOf(context.getSources(), name) && context.depth != 0) {
370+
if (property == null && context.depth != 0 && containsNoDescendantOf(context.getSources(), name)) {
371371
return null;
372372
}
373373
AggregateBinder<?> aggregateBinder = getAggregateBinder(target, context);

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -101,7 +101,7 @@ private void bindValue(Bindable<?> target, Collection<Object> collection, Resolv
101101

102102
private void bindIndexed(ConfigurationPropertySource source, ConfigurationPropertyName root,
103103
AggregateElementBinder elementBinder, IndexedCollectionSupplier collection, ResolvableType elementType) {
104-
MultiValueMap<String, ConfigurationProperty> knownIndexedChildren = getKnownIndexedChildren(source, root);
104+
MultiValueMap<String, ConfigurationPropertyName> knownIndexedChildren = getKnownIndexedChildren(source, root);
105105
for (int i = 0; i < Integer.MAX_VALUE; i++) {
106106
ConfigurationPropertyName name = root.append((i != 0) ? "[" + i + "]" : INDEX_ZERO);
107107
Object value = elementBinder.bind(name, Bindable.of(elementType), source);
@@ -111,30 +111,30 @@ private void bindIndexed(ConfigurationPropertySource source, ConfigurationProper
111111
knownIndexedChildren.remove(name.getLastElement(Form.UNIFORM));
112112
collection.get().add(value);
113113
}
114-
assertNoUnboundChildren(knownIndexedChildren);
114+
assertNoUnboundChildren(source, knownIndexedChildren);
115115
}
116116

117-
private MultiValueMap<String, ConfigurationProperty> getKnownIndexedChildren(ConfigurationPropertySource source,
117+
private MultiValueMap<String, ConfigurationPropertyName> getKnownIndexedChildren(ConfigurationPropertySource source,
118118
ConfigurationPropertyName root) {
119-
MultiValueMap<String, ConfigurationProperty> children = new LinkedMultiValueMap<>();
119+
MultiValueMap<String, ConfigurationPropertyName> children = new LinkedMultiValueMap<>();
120120
if (!(source instanceof IterableConfigurationPropertySource)) {
121121
return children;
122122
}
123123
for (ConfigurationPropertyName name : (IterableConfigurationPropertySource) source.filter(root::isAncestorOf)) {
124124
ConfigurationPropertyName choppedName = name.chop(root.getNumberOfElements() + 1);
125125
if (choppedName.isLastElementIndexed()) {
126126
String key = choppedName.getLastElement(Form.UNIFORM);
127-
ConfigurationProperty value = source.getConfigurationProperty(name);
128-
children.add(key, value);
127+
children.add(key, name);
129128
}
130129
}
131130
return children;
132131
}
133132

134-
private void assertNoUnboundChildren(MultiValueMap<String, ConfigurationProperty> children) {
133+
private void assertNoUnboundChildren(ConfigurationPropertySource source,
134+
MultiValueMap<String, ConfigurationPropertyName> children) {
135135
if (!children.isEmpty()) {
136-
throw new UnboundConfigurationPropertiesException(
137-
children.values().stream().flatMap(List::stream).collect(Collectors.toCollection(TreeSet::new)));
136+
throw new UnboundConfigurationPropertiesException(children.values().stream().flatMap(List::stream)
137+
.map(source::getConfigurationProperty).collect(Collectors.toCollection(TreeSet::new)));
138138
}
139139
}
140140

0 commit comments

Comments
 (0)