cacheBuffer does not need to be volatile

This commit is contained in:
themode 2022-02-20 13:15:46 +01:00
parent a15156aeb4
commit 62a7346f40

View File

@ -74,7 +74,7 @@ public class PlayerSocketConnection extends PlayerConnection {
private final List<BinaryBuffer> waitingBuffers = new ArrayList<>(); private final List<BinaryBuffer> waitingBuffers = new ArrayList<>();
private final AtomicReference<BinaryBuffer> tickBuffer = new AtomicReference<>(PooledBuffers.get()); private final AtomicReference<BinaryBuffer> tickBuffer = new AtomicReference<>(PooledBuffers.get());
private volatile BinaryBuffer cacheBuffer; private BinaryBuffer cacheBuffer;
private final ListenerHandle<PlayerPacketOutEvent> outgoing = EventDispatcher.getHandle(PlayerPacketOutEvent.class); private final ListenerHandle<PlayerPacketOutEvent> outgoing = EventDispatcher.getHandle(PlayerPacketOutEvent.class);
@ -124,8 +124,9 @@ public class PlayerSocketConnection extends PlayerConnection {
} }
public void consumeCache(BinaryBuffer buffer) { public void consumeCache(BinaryBuffer buffer) {
if (cacheBuffer != null) { final BinaryBuffer cache = this.cacheBuffer;
buffer.write(cacheBuffer); if (cache != null) {
buffer.write(cache);
this.cacheBuffer = null; this.cacheBuffer = null;
} }
} }