Optimize HttpHeaders.getAcceptLanguageAsLocales
The HttpHeaders.getAcceptLanguageAsLocales was incurring overhead from using a Stream, as well as calling the fairly expensive Locale.getDisplayName method. Switch to using an ArrayList, and skipping over wildcard ranges to avoid needing to check the display name. Closes gh-32318
This commit is contained in:
committed by
Arjen Poutsma
parent
d45c0e6b8a
commit
beb415dfa3
@@ -527,10 +527,14 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||
if (ranges.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return ranges.stream()
|
||||
.map(range -> Locale.forLanguageTag(range.getRange()))
|
||||
.filter(locale -> StringUtils.hasText(locale.getDisplayName()))
|
||||
.toList();
|
||||
|
||||
List<Locale> locales = new ArrayList<>(ranges.size());
|
||||
for (Locale.LanguageRange range : ranges) {
|
||||
if (!range.getRange().startsWith("*")) {
|
||||
locales.add(Locale.forLanguageTag(range.getRange()));
|
||||
}
|
||||
}
|
||||
return locales;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user