mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-17 05:31:23 +01:00
Reduce use of the pooled allocator
This commit is contained in:
parent
8b98472ddf
commit
f1e48b07b9
@ -1,6 +1,7 @@
|
|||||||
package net.minestom.server.network.packet.server.play;
|
package net.minestom.server.network.packet.server.play;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
@ -13,7 +14,6 @@ import net.minestom.server.instance.palette.Section;
|
|||||||
import net.minestom.server.network.packet.server.ServerPacket;
|
import net.minestom.server.network.packet.server.ServerPacket;
|
||||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||||
import net.minestom.server.utils.BlockPosition;
|
import net.minestom.server.utils.BlockPosition;
|
||||||
import net.minestom.server.utils.BufUtils;
|
|
||||||
import net.minestom.server.utils.Utils;
|
import net.minestom.server.utils.Utils;
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
import net.minestom.server.utils.binary.BinaryWriter;
|
import net.minestom.server.utils.binary.BinaryWriter;
|
||||||
@ -82,7 +82,7 @@ public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
|||||||
writer.writeBoolean(fullChunk);
|
writer.writeBoolean(fullChunk);
|
||||||
|
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
ByteBuf blocks = BufUtils.getBuffer(MAX_BUFFER_SIZE);
|
ByteBuf blocks = Unpooled.buffer(MAX_BUFFER_SIZE);
|
||||||
for (byte i = 0; i < CHUNK_SECTION_COUNT; i++) {
|
for (byte i = 0; i < CHUNK_SECTION_COUNT; i++) {
|
||||||
if (fullChunk || (sections.length == CHUNK_SECTION_COUNT && sections[i] != 0)) {
|
if (fullChunk || (sections.length == CHUNK_SECTION_COUNT && sections[i] != 0)) {
|
||||||
final Section section = paletteStorage.getSections()[i];
|
final Section section = paletteStorage.getSections()[i];
|
||||||
|
@ -62,7 +62,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
|||||||
private PlayerSkin bungeeSkin;
|
private PlayerSkin bungeeSkin;
|
||||||
|
|
||||||
private final Object tickBufferLock = new Object();
|
private final Object tickBufferLock = new Object();
|
||||||
private volatile ByteBuf tickBuffer = BufUtils.getBuffer(true);
|
private volatile ByteBuf tickBuffer = BufUtils.direct();
|
||||||
|
|
||||||
public NettyPlayerConnection(@NotNull SocketChannel channel) {
|
public NettyPlayerConnection(@NotNull SocketChannel channel) {
|
||||||
super();
|
super();
|
||||||
|
@ -7,28 +7,11 @@ public class BufUtils {
|
|||||||
|
|
||||||
private static final PooledByteBufAllocator alloc = PooledByteBufAllocator.DEFAULT;
|
private static final PooledByteBufAllocator alloc = PooledByteBufAllocator.DEFAULT;
|
||||||
|
|
||||||
public static ByteBuf getBuffer() {
|
public static ByteBuf direct() {
|
||||||
return alloc.heapBuffer();
|
return alloc.ioBuffer();
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuf getBuffer(boolean io) {
|
|
||||||
return io ? alloc.ioBuffer() : alloc.heapBuffer();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ByteBuf getBuffer(int initialCapacity) {
|
public static ByteBuf getBuffer(int initialCapacity) {
|
||||||
return alloc.heapBuffer(initialCapacity);
|
return alloc.heapBuffer(initialCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ByteBuf getBuffer(boolean io, int initialCapacity) {
|
|
||||||
return io ? alloc.ioBuffer(initialCapacity) : alloc.heapBuffer(initialCapacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuf getBuffer(int initialCapacity, int maxCapacity) {
|
|
||||||
return alloc.heapBuffer(initialCapacity, maxCapacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ByteBuf getBuffer(boolean io, int initialCapacity, int maxCapacity) {
|
|
||||||
return io ? alloc.ioBuffer(initialCapacity, maxCapacity) : alloc.heapBuffer(initialCapacity, maxCapacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import net.minestom.server.utils.callback.validator.PlayerValidator;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.zip.DataFormatException;
|
import java.util.zip.DataFormatException;
|
||||||
|
|
||||||
@ -287,7 +286,7 @@ public final class PacketUtils {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ByteBuf createFramedPacket(@NotNull ServerPacket serverPacket, boolean directBuffer) {
|
public static ByteBuf createFramedPacket(@NotNull ServerPacket serverPacket, boolean directBuffer) {
|
||||||
ByteBuf packetBuf = directBuffer ? BufUtils.getBuffer(true) : Unpooled.buffer();
|
ByteBuf packetBuf = directBuffer ? BufUtils.direct() : Unpooled.buffer();
|
||||||
writeFramedPacket(packetBuf, serverPacket);
|
writeFramedPacket(packetBuf, serverPacket);
|
||||||
return packetBuf;
|
return packetBuf;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user