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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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); methods.add(method);
} }
}, ReflectionUtils.USER_DECLARED_METHODS); }, ReflectionUtils.USER_DECLARED_METHODS);
if (methods.size() > 1) {
methods.sort(METHOD_COMPARATOR); methods.sort(METHOD_COMPARATOR);
}
return methods; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -398,6 +398,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@Override @Override
public Stream<T> orderedStream() { public Stream<T> orderedStream() {
String[] beanNames = getBeanNamesForTypedStream(requiredType); String[] beanNames = getBeanNamesForTypedStream(requiredType);
if (beanNames.length == 0) {
return Stream.empty();
}
Map<String, T> matchingBeans = new LinkedHashMap<>(beanNames.length); Map<String, T> matchingBeans = new LinkedHashMap<>(beanNames.length);
for (String beanName : beanNames) { for (String beanName : beanNames) {
Object beanInstance = getBean(beanName); Object beanInstance = getBean(beanName);
@ -1366,11 +1369,13 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter()); TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
Object result = converter.convertIfNecessary(matchingBeans.values(), type); Object result = converter.convertIfNecessary(matchingBeans.values(), type);
if (result instanceof List) { if (result instanceof List) {
if (((List<?>) result).size() > 1) {
Comparator<Object> comparator = adaptDependencyComparator(matchingBeans); Comparator<Object> comparator = adaptDependencyComparator(matchingBeans);
if (comparator != null) { if (comparator != null) {
((List<?>) result).sort(comparator); ((List<?>) result).sort(comparator);
} }
} }
}
return result; return result;
} }
else if (Map.class == type) { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public ConsumesRequestCondition(String[] consumes, String[] headers) {
this.expressions = new ArrayList<>(parseExpressions(consumes, headers)); this.expressions = new ArrayList<>(parseExpressions(consumes, headers));
if (this.expressions.size() > 1) {
Collections.sort(this.expressions); Collections.sort(this.expressions);
} }
}
/** /**
* Private constructor for internal when creating matching conditions. * 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public ProducesRequestCondition(String[] produces, String[] headers, RequestedContentTypeResolver resolver) {
this.expressions = new ArrayList<>(parseExpressions(produces, headers)); this.expressions = new ArrayList<>(parseExpressions(produces, headers));
if (this.expressions.size() > 1) {
Collections.sort(this.expressions); Collections.sort(this.expressions);
}
this.contentTypeResolver = resolver != null ? resolver : DEFAULT_CONTENT_TYPE_RESOLVER; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public ConsumesRequestCondition(String[] consumes, @Nullable String[] headers) {
this.expressions = new ArrayList<>(parseExpressions(consumes, headers)); this.expressions = new ArrayList<>(parseExpressions(consumes, headers));
if (this.expressions.size() > 1) {
Collections.sort(this.expressions); Collections.sort(this.expressions);
} }
}
/** /**
* Private constructor for internal when creating matching conditions. * 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { @Nullable ContentNegotiationManager manager) {
this.expressions = new ArrayList<>(parseExpressions(produces, headers)); this.expressions = new ArrayList<>(parseExpressions(produces, headers));
if (this.expressions.size() > 1) {
Collections.sort(this.expressions); Collections.sort(this.expressions);
}
this.contentNegotiationManager = manager != null ? manager : DEFAULT_CONTENT_NEGOTIATION_MANAGER; this.contentNegotiationManager = manager != null ? manager : DEFAULT_CONTENT_NEGOTIATION_MANAGER;
} }