Start optimizing server list ping.

This commit is contained in:
Andrew Steinborn
2020-10-04 15:30:28 -04:00
parent cb74210cd8
commit 3bf252cf45
10 changed files with 216 additions and 39 deletions

View File

@@ -63,6 +63,23 @@ public class LibdeflateVelocityCompressor implements VelocityCompressor {
}
}
@Override
public boolean deflateSingle(ByteBuf source, ByteBuf destination) throws DataFormatException {
ensureNotDisposed();
long sourceAddress = source.memoryAddress() + source.readerIndex();
long destinationAddress = destination.memoryAddress() + destination.writerIndex();
int produced = deflate.process(deflateCtx, sourceAddress, source.readableBytes(),
destinationAddress, destination.writableBytes());
if (produced > 0) {
destination.writerIndex(destination.writerIndex() + produced);
return true;
}
return false;
}
private void ensureNotDisposed() {
Preconditions.checkState(!disposed, "Object already disposed");
}

View File

@@ -14,4 +14,9 @@ public interface VelocityCompressor extends Disposable, Native {
throws DataFormatException;
void deflate(ByteBuf source, ByteBuf destination) throws DataFormatException;
default boolean deflateSingle(ByteBuf source, ByteBuf destination) throws DataFormatException {
deflate(source, destination);
return true;
}
}