Avoid Needless Set Instantiation in InboundMessage (#44318) (#44329)

* Avoid Needless Set Instantiation in InboundMessage

* When `features` is empty (when there's no xpack) we constantly and needless instantiated a few objects here for the empty set on every message
This commit is contained in:
Armin Braun 2019-07-15 10:59:51 +02:00 committed by GitHub
parent 0cc94a457d
commit 7f5d40d235
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -101,7 +101,12 @@ public abstract class InboundMessage extends NetworkMessage implements Closeable
if (TransportStatus.isRequest(status)) {
final Set<String> features;
if (remoteVersion.onOrAfter(Version.V_6_3_0)) {
features = Collections.unmodifiableSet(new TreeSet<>(Arrays.asList(streamInput.readStringArray())));
final String[] featuresFound = streamInput.readStringArray();
if (featuresFound.length == 0) {
features = Collections.emptySet();
} else {
features = Collections.unmodifiableSet(new TreeSet<>(Arrays.asList(featuresFound)));
}
} else {
features = Collections.emptySet();
}