From 9c5c23c7af05b8d306efd018e2994c5a52018d5f Mon Sep 17 00:00:00 2001 From: godotg Date: Fri, 23 Sep 2022 21:04:03 +0800 Subject: [PATCH] =?UTF-8?q?perf[list]:=20=E4=BD=BF=E7=94=A8=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E6=9B=B4=E9=AB=98=E7=9A=84FixList=E5=8F=8D=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96List=E9=9B=86=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zfoo/protocol/buffer/ByteBufUtils.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 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 5e2bd816..3ce7db6a 100644 --- a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java @@ -13,8 +13,7 @@ package com.zfoo.protocol.buffer; import com.zfoo.protocol.IPacket; -import com.zfoo.protocol.collection.ArrayUtils; -import com.zfoo.protocol.collection.CollectionUtils; +import com.zfoo.protocol.collection.*; import com.zfoo.protocol.registration.IProtocolRegistration; import com.zfoo.protocol.util.StringUtils; import io.netty.buffer.ByteBuf; @@ -754,9 +753,9 @@ public abstract class ByteBufUtils { public static List readBooleanList(ByteBuf byteBuf) { var length = readInt(byteBuf); - var list = (List) CollectionUtils.newFixedList(length); + var list = new FixedSizeBooleanList(length); for (var i = 0; i < length; i++) { - list.add(readBooleanBox(byteBuf)); + list.set(i, readBoolean(byteBuf)); } return list; } @@ -918,9 +917,9 @@ public abstract class ByteBufUtils { public static List readShortList(ByteBuf byteBuf) { var length = readInt(byteBuf); - var list = (List) CollectionUtils.newFixedList(length); + var list = new FixedSizeShortList(length); for (var i = 0; i < length; i++) { - list.add(readShortBox(byteBuf)); + list.set(i, readShort(byteBuf)); } return list; } @@ -997,9 +996,9 @@ public abstract class ByteBufUtils { public static List readIntList(ByteBuf byteBuf) { var length = readInt(byteBuf); - var list = (List) CollectionUtils.newFixedList(length); + var list = new FixedSizeIntList(length); for (var i = 0; i < length; i++) { - list.add(readIntBox(byteBuf)); + list.set(i, readInt(byteBuf)); } return list; } @@ -1076,9 +1075,9 @@ public abstract class ByteBufUtils { public static List readLongList(ByteBuf byteBuf) { var length = readInt(byteBuf); - var list = (List) CollectionUtils.newFixedList(length); + var list = new FixedSizeLongList(length); for (var i = 0; i < length; i++) { - list.add(readLongBox(byteBuf)); + list.set(i, readLong(byteBuf)); } return list; } @@ -1162,9 +1161,9 @@ public abstract class ByteBufUtils { public static List readFloatList(ByteBuf byteBuf) { var length = readInt(byteBuf); - var list = (List) CollectionUtils.newFixedList(length); + var list = new FixedSizeFloatList(length); for (var i = 0; i < length; i++) { - list.add(readFloatBox(byteBuf)); + list.set(i, readFloat(byteBuf)); } return list; } @@ -1248,9 +1247,9 @@ public abstract class ByteBufUtils { public static List readDoubleList(ByteBuf byteBuf) { var length = readInt(byteBuf); - var list = (List) CollectionUtils.newFixedList(length); + var list = new FixedSizeDoubleList(length); for (var i = 0; i < length; i++) { - list.add(readDoubleBox(byteBuf)); + list.set(i, readDouble(byteBuf)); } return list; } @@ -1306,9 +1305,9 @@ public abstract class ByteBufUtils { public static List readStringList(ByteBuf byteBuf) { var length = readInt(byteBuf); - var list = (List) CollectionUtils.newFixedList(length); + var list = new FixedSizeStringList(length); for (var i = 0; i < length; i++) { - list.add(readString(byteBuf)); + list.set(i, readString(byteBuf)); } return list; }