mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
Avoid creating batch buffers just to determine whether a batch should be globally compressed
Instead, sum together the lengths of encoded packet buffers and use that to decide whether to build the buffer or not.
This commit is contained in:
@ -32,7 +32,7 @@ use function zlib_decode;
|
||||
use function zlib_encode;
|
||||
use const ZLIB_ENCODING_RAW;
|
||||
|
||||
final class ZlibCompressor implements Compressor{
|
||||
final class ZlibCompressor implements ThresholdCompressor{
|
||||
use SingletonTrait;
|
||||
|
||||
public const DEFAULT_LEVEL = 7;
|
||||
@ -48,12 +48,16 @@ final class ZlibCompressor implements Compressor{
|
||||
|
||||
public function __construct(
|
||||
private int $level,
|
||||
private int $minCompressionSize,
|
||||
private ?int $minCompressionSize,
|
||||
private int $maxDecompressionSize
|
||||
){}
|
||||
|
||||
public function getCompressionThreshold() : ?int{
|
||||
return $this->minCompressionSize;
|
||||
}
|
||||
|
||||
public function willCompress(string $data) : bool{
|
||||
return $this->minCompressionSize > -1 && strlen($data) >= $this->minCompressionSize;
|
||||
return $this->minCompressionSize !== null && strlen($data) >= $this->minCompressionSize;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user