Filter out duplicates before trying to find the alias to use (#10612)

Motivation:

Calling chooseServerAlias(...) may be expensive so we should ensure we not call it multiple times for the same auth methods.

Modifications:

Remove duplicated from authMethods before trying to call chooseServerAlias(...)

Result:

Less performance overhead during key material selection
This commit is contained in:
Norman Maurer 2020-09-25 19:12:28 +02:00 committed by GitHub
parent a4276e8dff
commit 6bda0fd082
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,8 +21,10 @@ import javax.net.ssl.X509KeyManager;
import javax.security.auth.x500.X500Principal;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
@ -68,8 +70,12 @@ final class OpenSslKeyMaterialManager {
if (authMethods.length == 0) {
return;
}
Set<String> aliases = new HashSet<String>(authMethods.length);
for (String authMethod : authMethods) {
// authMethods may contain duplicates but call chooseServerAlias(...) may be expensive. So let's ensure
// we filter out duplicates.
Set<String> authMethodsSet = new LinkedHashSet<String>(authMethods.length);
Collections.addAll(authMethodsSet, authMethods);
Set<String> aliases = new HashSet<String>(authMethodsSet.size());
for (String authMethod : authMethodsSet) {
String type = KEY_TYPES.get(authMethod);
if (type != null) {
String alias = chooseServerAlias(engine, type);