Skip to content

Commit 8561729

Browse files
qianye1001web-flowclaude
authored
[ISSUE #10400] Cache Version.values() in MQVersion to avoid repeated array allocation (#10401)
Co-authored-by: Qoder CLI <noreply@github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e12d755 commit 8561729

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

common/src/main/java/org/apache/rocketmq/common/MQVersion.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,24 @@ public class MQVersion {
2020

2121
public static final int CURRENT_VERSION = Version.V5_5_0.ordinal();
2222

23+
private static final Version[] VERSION_VALUES = Version.values();
24+
2325
public static String getVersionDesc(int value) {
24-
int length = Version.values().length;
26+
Version[] versions = VERSION_VALUES;
27+
int length = versions.length;
2528
if (value >= length) {
26-
return Version.values()[length - 1].name();
29+
return versions[length - 1].name();
2730
}
28-
29-
return Version.values()[value].name();
31+
return versions[value].name();
3032
}
3133

3234
public static Version value2Version(int value) {
33-
int length = Version.values().length;
35+
Version[] versions = VERSION_VALUES;
36+
int length = versions.length;
3437
if (value >= length) {
35-
return Version.values()[length - 1];
38+
return versions[length - 1];
3639
}
37-
38-
return Version.values()[value];
40+
return versions[value];
3941
}
4042

4143
public enum Version {

0 commit comments

Comments
 (0)