This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8561729a14 [ISSUE #10400] Cache Version.values() in MQVersion to avoid 
repeated array allocation (#10401)
8561729a14 is described below

commit 8561729a1433b1bdb298d476b2dde374a8766990
Author: qianye <[email protected]>
AuthorDate: Mon Jun 1 10:51:36 2026 +0800

    [ISSUE #10400] Cache Version.values() in MQVersion to avoid repeated array 
allocation (#10401)
    
    Co-authored-by: Qoder CLI <[email protected]>
    Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 .../java/org/apache/rocketmq/common/MQVersion.java     | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/common/src/main/java/org/apache/rocketmq/common/MQVersion.java 
b/common/src/main/java/org/apache/rocketmq/common/MQVersion.java
index ffebaae415..0c92781403 100644
--- a/common/src/main/java/org/apache/rocketmq/common/MQVersion.java
+++ b/common/src/main/java/org/apache/rocketmq/common/MQVersion.java
@@ -20,22 +20,24 @@ public class MQVersion {
 
     public static final int CURRENT_VERSION = Version.V5_5_0.ordinal();
 
+    private static final Version[] VERSION_VALUES = Version.values();
+
     public static String getVersionDesc(int value) {
-        int length = Version.values().length;
+        Version[] versions = VERSION_VALUES;
+        int length = versions.length;
         if (value >= length) {
-            return Version.values()[length - 1].name();
+            return versions[length - 1].name();
         }
-
-        return Version.values()[value].name();
+        return versions[value].name();
     }
 
     public static Version value2Version(int value) {
-        int length = Version.values().length;
+        Version[] versions = VERSION_VALUES;
+        int length = versions.length;
         if (value >= length) {
-            return Version.values()[length - 1];
+            return versions[length - 1];
         }
-
-        return Version.values()[value];
+        return versions[value];
     }
 
     public enum Version {

Reply via email to