From c664a24f984d78b70eb568932f8b5a62d2e55697 Mon Sep 17 00:00:00 2001 From: jaysunxiao Date: Sun, 23 May 2021 17:50:40 +0800 Subject: [PATCH] =?UTF-8?q?perf[protocol]:=20=E5=87=8F=E5=B0=91=E5=86=99?= =?UTF-8?q?=E5=85=A5long=E7=9A=84=E6=97=B6=E5=80=99=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84zigzag=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/zfoo/protocol/buffer/ByteBufUtils.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java index 29fbfa7b..102e83ba 100644 --- a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java @@ -90,8 +90,10 @@ public abstract class ByteBufUtils { //---------------------------------int-------------------------------------- // 用Zigzag算法压缩int和long的值,再用Varint紧凑算法表示数字的有效位 public static int writeInt(ByteBuf byteBuf, int value) { - value = (value << 1) ^ (value >> 31); + return writeVarInt(byteBuf, (value << 1) ^ (value >> 31)); + } + private static int writeVarInt(ByteBuf byteBuf, int value) { int a = value >>> 7; if (a == 0) { byteBuf.writeByte(value); @@ -191,7 +193,7 @@ public abstract class ByteBufUtils { long mask = (value << 1) ^ (value >> 63); if (mask >>> 32 == 0) { - writeInt(byteBuf, (int) value); + writeVarInt(byteBuf, (int) mask); return; }