Improve Binder performance slightly
See gh-20755
This commit is contained in:
committed by
Stephane Nicoll
parent
0611b6d3eb
commit
43936d66d3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -367,7 +367,7 @@ public class Binder {
|
||||
private <T> Object bindObject(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler,
|
||||
Context context, boolean allowRecursiveBinding) {
|
||||
ConfigurationProperty property = findProperty(name, context);
|
||||
if (property == null && containsNoDescendantOf(context.getSources(), name) && context.depth != 0) {
|
||||
if (property == null && context.depth != 0 && containsNoDescendantOf(context.getSources(), name)) {
|
||||
return null;
|
||||
}
|
||||
AggregateBinder<?> aggregateBinder = getAggregateBinder(target, context);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -101,7 +101,7 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
|
||||
|
||||
private void bindIndexed(ConfigurationPropertySource source, ConfigurationPropertyName root,
|
||||
AggregateElementBinder elementBinder, IndexedCollectionSupplier collection, ResolvableType elementType) {
|
||||
MultiValueMap<String, ConfigurationProperty> knownIndexedChildren = getKnownIndexedChildren(source, root);
|
||||
MultiValueMap<String, ConfigurationPropertyName> knownIndexedChildren = getKnownIndexedChildren(source, root);
|
||||
for (int i = 0; i < Integer.MAX_VALUE; i++) {
|
||||
ConfigurationPropertyName name = root.append((i != 0) ? "[" + i + "]" : INDEX_ZERO);
|
||||
Object value = elementBinder.bind(name, Bindable.of(elementType), source);
|
||||
@@ -111,12 +111,12 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
|
||||
knownIndexedChildren.remove(name.getLastElement(Form.UNIFORM));
|
||||
collection.get().add(value);
|
||||
}
|
||||
assertNoUnboundChildren(knownIndexedChildren);
|
||||
assertNoUnboundChildren(source, knownIndexedChildren);
|
||||
}
|
||||
|
||||
private MultiValueMap<String, ConfigurationProperty> getKnownIndexedChildren(ConfigurationPropertySource source,
|
||||
private MultiValueMap<String, ConfigurationPropertyName> getKnownIndexedChildren(ConfigurationPropertySource source,
|
||||
ConfigurationPropertyName root) {
|
||||
MultiValueMap<String, ConfigurationProperty> children = new LinkedMultiValueMap<>();
|
||||
MultiValueMap<String, ConfigurationPropertyName> children = new LinkedMultiValueMap<>();
|
||||
if (!(source instanceof IterableConfigurationPropertySource)) {
|
||||
return children;
|
||||
}
|
||||
@@ -124,17 +124,17 @@ abstract class IndexedElementsBinder<T> extends AggregateBinder<T> {
|
||||
ConfigurationPropertyName choppedName = name.chop(root.getNumberOfElements() + 1);
|
||||
if (choppedName.isLastElementIndexed()) {
|
||||
String key = choppedName.getLastElement(Form.UNIFORM);
|
||||
ConfigurationProperty value = source.getConfigurationProperty(name);
|
||||
children.add(key, value);
|
||||
children.add(key, name);
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
private void assertNoUnboundChildren(MultiValueMap<String, ConfigurationProperty> children) {
|
||||
private void assertNoUnboundChildren(ConfigurationPropertySource source,
|
||||
MultiValueMap<String, ConfigurationPropertyName> children) {
|
||||
if (!children.isEmpty()) {
|
||||
throw new UnboundConfigurationPropertiesException(
|
||||
children.values().stream().flatMap(List::stream).collect(Collectors.toCollection(TreeSet::new)));
|
||||
throw new UnboundConfigurationPropertiesException(children.values().stream().flatMap(List::stream)
|
||||
.map(source::getConfigurationProperty).collect(Collectors.toCollection(TreeSet::new)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user