Avoid unnecessary sorting

This commit is contained in:
Christoph Dreis
2020-02-29 15:29:04 +01:00
committed by Rossen Stoyanchev
parent 87230c4f1f
commit 2093e35f27
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.
@@ -77,7 +77,9 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
*/
public ConsumesRequestCondition(String[] consumes, @Nullable String[] headers) {
this.expressions = new ArrayList<>(parseExpressions(consumes, headers));
Collections.sort(this.expressions);
if (this.expressions.size() > 1) {
Collections.sort(this.expressions);
}
}
/**

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));
Collections.sort(this.expressions);
if (this.expressions.size() > 1) {
Collections.sort(this.expressions);
}
this.contentNegotiationManager = manager != null ? manager : DEFAULT_CONTENT_NEGOTIATION_MANAGER;
}