Skip to content

Commit

Permalink
[INLONG-9893][Common] Optimized code InLongMsg (#9894)
Browse files Browse the repository at this point in the history
  • Loading branch information
beatCao and [email protected] authored Mar 31, 2024
1 parent 5b5eabb commit 595bb12
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,9 @@ public boolean addMsg(String attr, ByteBuffer data) {
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 {
Expand Down Expand Up @@ -394,9 +390,10 @@ private ByteBuffer defaultBuild(long createtime) {
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);
}
Expand All @@ -410,9 +407,10 @@ private ByteBuffer defaultBuild(long createtime) {
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);
}
Expand Down

0 comments on commit 595bb12

Please sign in to comment.