This is an automated email from the ASF dual-hosted git repository.
dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new 595bb12d75 [INLONG-9893][Common] Optimized code InLongMsg (#9894)
595bb12d75 is described below
commit 595bb12d75c0cf6743bfeb3eae2e78936a300f63
Author: beatCao <[email protected]>
AuthorDate: Sun Mar 31 23:07:39 2024 +0800
[INLONG-9893][Common] Optimized code InLongMsg (#9894)
Co-authored-by: [email protected] <[email protected]>
---
.../java/org/apache/inlong/common/msg/InLongMsg.java | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git
a/inlong-common/src/main/java/org/apache/inlong/common/msg/InLongMsg.java
b/inlong-common/src/main/java/org/apache/inlong/common/msg/InLongMsg.java
index 005ad41ee1..7c15a23a54 100644
--- a/inlong-common/src/main/java/org/apache/inlong/common/msg/InLongMsg.java
+++ b/inlong-common/src/main/java/org/apache/inlong/common/msg/InLongMsg.java
@@ -246,13 +246,9 @@ public class InLongMsg {
return false;
}
- DataBuffer outputBuffer = attr2MsgBuffer.get(attr);
- if (outputBuffer == null) {
- outputBuffer = new DataBuffer();
- attr2MsgBuffer.put(attr, outputBuffer);
- // attrlen + utflen + meglen + compress
- this.datalen += attr.length() + 2 + 4 + 1;
- }
+ DataBuffer outputBuffer = attr2MsgBuffer.computeIfAbsent(attr, k ->
new DataBuffer());
+ // attrlen + utflen + meglen + compress
+ this.datalen += attr.length() + 2 + 4 + 1;
int len = data.remaining();
try {
@@ -394,9 +390,10 @@ public class InLongMsg {
out.writeInt(attr2MsgBuffer.size());
if (compress) {
- for (String attr : attr2MsgBuffer.keySet()) {
+ for (Map.Entry<String, DataBuffer> entry :
attr2MsgBuffer.entrySet()) {
+ String attr = entry.getKey();
+ DataBuffer data = entry.getValue();
out.writeUTF(attr);
- DataBuffer data = attr2MsgBuffer.get(attr);
if (version.intValue() == Version.v2.intValue()) {
out.writeInt(data.cnt);
}
@@ -410,9 +407,10 @@ public class InLongMsg {
out.write(tmpData, 0, len);
}
} else {
- for (String attr : attr2MsgBuffer.keySet()) {
+ for (Map.Entry<String, DataBuffer> entry :
attr2MsgBuffer.entrySet()) {
+ String attr = entry.getKey();
+ DataBuffer data = entry.getValue();
out.writeUTF(attr);
- DataBuffer data = attr2MsgBuffer.get(attr);
if (version.intValue() == Version.v2.intValue()) {
out.writeInt(data.cnt);
}