3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-25 15:50:19 +01:00

We don't need to retain/release the mod list buffer in readModList

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-11-05 20:04:31 -05:00
Ursprung 91b295ead5
Commit cc89a2a1e5

Datei anzeigen

@ -39,31 +39,25 @@ class LegacyForgeUtil {
*/ */
static List<ModInfo.Mod> readModList(PluginMessage message) { static List<ModInfo.Mod> readModList(PluginMessage message) {
Preconditions.checkNotNull(message, "message"); Preconditions.checkNotNull(message, "message");
Preconditions Preconditions.checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL),
.checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL),
"message is not a FML HS plugin message"); "message is not a FML HS plugin message");
ByteBuf byteBuf = message.content().retainedSlice(); ByteBuf contents = message.content().slice();
try { byte discriminator = contents.readByte();
byte discriminator = byteBuf.readByte(); if (discriminator == MOD_LIST_DISCRIMINATOR) {
ImmutableList.Builder<ModInfo.Mod> mods = ImmutableList.builder();
int modCount = ProtocolUtils.readVarInt(contents);
if (discriminator == MOD_LIST_DISCRIMINATOR) { for (int index = 0; index < modCount; index++) {
ImmutableList.Builder<ModInfo.Mod> mods = ImmutableList.builder(); String id = ProtocolUtils.readString(contents);
int modCount = ProtocolUtils.readVarInt(byteBuf); String version = ProtocolUtils.readString(contents);
mods.add(new ModInfo.Mod(id, version));
for (int index = 0; index < modCount; index++) {
String id = ProtocolUtils.readString(byteBuf);
String version = ProtocolUtils.readString(byteBuf);
mods.add(new ModInfo.Mod(id, version));
}
return mods.build();
} }
return ImmutableList.of(); return mods.build();
} finally {
byteBuf.release();
} }
return ImmutableList.of();
} }
/** /**