Merge pull reqest #24617 from dreis2211/avoid-unnecessary-sorting

Closes gh-24617
This commit is contained in:
Rossen Stoyanchev 2020-03-04 19:16:10 +00:00
commit e7df445e37
6 changed files with 29 additions and 14 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-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.
@ -154,7 +154,9 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
methods.add(method);
}
}, ReflectionUtils.USER_DECLARED_METHODS);
if (methods.size() > 1) {
methods.sort(METHOD_COMPARATOR);
}
return methods;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-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.
@ -398,6 +398,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@Override
public Stream<T> orderedStream() {
String[] beanNames = getBeanNamesForTypedStream(requiredType);
if (beanNames.length == 0) {
return Stream.empty();
}
Map<String, T> matchingBeans = new LinkedHashMap<>(beanNames.length);
for (String beanName : beanNames) {
Object beanInstance = getBean(beanName);
@ -1366,11 +1369,13 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
Object result = converter.convertIfNecessary(matchingBeans.values(), type);
if (result instanceof List) {
if (((List<?>) result).size() > 1) {
Comparator<Object> comparator = adaptDependencyComparator(matchingBeans);
if (comparator != null) {
((List<?>) result).sort(comparator);
}
}
}
return result;
}
else if (Map.class == type) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-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.
@ -76,8 +76,10 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
*/
public ConsumesRequestCondition(String[] consumes, String[] headers) {
this.expressions = new ArrayList<>(parseExpressions(consumes, headers));
if (this.expressions.size() > 1) {
Collections.sort(this.expressions);
}
}
/**
* Private constructor for internal when creating matching conditions.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-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.
@ -93,7 +93,9 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
*/
public ProducesRequestCondition(String[] produces, String[] headers, RequestedContentTypeResolver resolver) {
this.expressions = new ArrayList<>(parseExpressions(produces, headers));
if (this.expressions.size() > 1) {
Collections.sort(this.expressions);
}
this.contentTypeResolver = resolver != null ? resolver : DEFAULT_CONTENT_TYPE_RESOLVER;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-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.
@ -77,8 +77,10 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
*/
public ConsumesRequestCondition(String[] consumes, @Nullable String[] headers) {
this.expressions = new ArrayList<>(parseExpressions(consumes, headers));
if (this.expressions.size() > 1) {
Collections.sort(this.expressions);
}
}
/**
* Private constructor for internal when creating matching conditions.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-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.
@ -97,7 +97,9 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
@Nullable ContentNegotiationManager manager) {
this.expressions = new ArrayList<>(parseExpressions(produces, headers));
if (this.expressions.size() > 1) {
Collections.sort(this.expressions);
}
this.contentNegotiationManager = manager != null ? manager : DEFAULT_CONTENT_NEGOTIATION_MANAGER;
}