Skip to content

Commit e10e5b9

Browse files
author
Matt Byrd
committed
compute ProtocolVersion::supportedVersions once immutably to avoid object generation
patch by Matt Byrd; reviewed by for CASSANDRA-21199
1 parent fbf1137 commit e10e5b9

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
7.0
2+
* compute ProtocolVersion::supportedVersions once immutably to avoid object generation (CASSANDRA-21199)
23
* Avoid using ObjectUtils.getFirstNonNull in Schema (CASSANDRA-21394)
34
* Allow nodetool garbagecollect to take a user defined list of SSTables (CASSANDRA-16767)
45
* Add a guardrail for misprepared statements (CASSANDRA-21139)

src/java/org/apache/cassandra/transport/ProtocolVersion.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.List;
2525
import java.util.Optional;
2626

27+
import com.google.common.collect.ImmutableList;
28+
2729
import org.apache.commons.lang3.ArrayUtils;
2830

2931
import org.apache.cassandra.cql3.FunctionContext;
@@ -73,6 +75,7 @@ public enum ProtocolVersion implements Comparable<ProtocolVersion>, FunctionCont
7375

7476
/** All supported versions, published as an enumset */
7577
public final static EnumSet<ProtocolVersion> SUPPORTED = EnumSet.copyOf(Arrays.asList(ArrayUtils.addAll(SUPPORTED_VERSIONS)));
78+
private final static ImmutableList<String> SUPPORTED_VERSION_STRINGS = SUPPORTED.stream().map(ProtocolVersion::toString).collect(ImmutableList.toImmutableList());
7679

7780
/** Old unsupported versions, this is OK as long as we never add newer unsupported versions */
7881
public final static EnumSet<ProtocolVersion> UNSUPPORTED = EnumSet.complementOf(SUPPORTED);
@@ -84,12 +87,9 @@ public enum ProtocolVersion implements Comparable<ProtocolVersion>, FunctionCont
8487
public final static ProtocolVersion CURRENT = V5;
8588
public final static Optional<ProtocolVersion> BETA = Optional.of(V6);
8689

87-
public static List<String> supportedVersions()
90+
public static ImmutableList<String> supportedVersions()
8891
{
89-
List<String> ret = new ArrayList<>(SUPPORTED.size());
90-
for (ProtocolVersion version : SUPPORTED)
91-
ret.add(version.toString());
92-
return ret;
92+
return SUPPORTED_VERSION_STRINGS;
9393
}
9494

9595
public static List<ProtocolVersion> supportedVersionsStartingWith(ProtocolVersion smallestVersion)

0 commit comments

Comments
 (0)