wang-jiahua commented on code in PR #10444:
URL: https://github.com/apache/rocketmq/pull/10444#discussion_r3373798269


##########
common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java:
##########
@@ -725,7 +1034,8 @@ public static Message decodeMessage(ByteBuffer byteBuffer) 
throws Exception {
         short propertiesLen = byteBuffer.getShort();
         byte[] propertiesBytes = new byte[propertiesLen];
         byteBuffer.get(propertiesBytes);
-        message.setProperties(string2messageProperties(new 
String(propertiesBytes, CHARSET_UTF8)));
+        // opt16: parse directly from bytes; skip the intermediate String 
allocation.
+        message.setProperties(bytes2messageProperties(propertiesBytes, 0, 
propertiesLen));

Review Comment:
   Resolved: `decodeMessage` now stores the standard `HashMap` returned by 
`bytes2messageProperties`, so `Entry.setValue()` and the rest of the `HashMap` 
contract are preserved. The `FlatPropertiesMap` class has been removed 
entirely. Covered by `testBytes2messagePropertiesReturnsIndependentMap`.



##########
common/src/main/java/org/apache/rocketmq/common/message/MessageExtBrokerInner.java:
##########
@@ -59,13 +63,39 @@ public String getPropertiesString() {
 
     public void setPropertiesString(String propertiesString) {
         this.propertiesString = propertiesString;
+        this.propertiesData = null;
+    }
+
+    public byte[] getPropertiesData() {
+        return propertiesData;
+    }

Review Comment:
   Fixed: the public `getPropertiesData()` now returns a defensive copy via 
`propertiesData.clone()`, so external callers cannot mutate the cached encoded 
bytes. The encode hot path uses `getEffectivePropertiesData()`, which has been 
made package-private and documents that the returned array is the internal 
buffer and must not be mutated.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to