fixed performance bug
This commit is contained in:
@@ -3,8 +3,6 @@ package net.woggioni.jzstd
|
||||
import com.beust.jcommander.JCommander
|
||||
import com.beust.jcommander.Parameter
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.BufferedInputStream
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.nio.file.Files
|
||||
@@ -32,7 +30,7 @@ object Cli {
|
||||
var overwrite: Boolean = false,
|
||||
|
||||
@Parameter(names = arrayOf("-l", "--level"), description = "Set compression level")
|
||||
var level: Int = 3,
|
||||
var level: Int = 0,
|
||||
|
||||
@Parameter(names = arrayOf("-i", "--input"), description = "Set input file, defaults to stdin otherwise")
|
||||
var input: String? = null,
|
||||
@@ -110,7 +108,7 @@ object Cli {
|
||||
else it
|
||||
}
|
||||
output.use { outputStream ->
|
||||
val buffer = ByteArray(0x10000)
|
||||
val buffer = ByteArray(0x1000)
|
||||
while (true) {
|
||||
val read = inputStream.read(buffer, 0, buffer.size)
|
||||
if (read < 0) break
|
||||
|
@@ -16,7 +16,7 @@ public class ZstdOutputStream extends OutputStream {
|
||||
|
||||
private static final int inputBufferSize = ZstdLibrary.CStreamInSize();
|
||||
private static final int outputBufferSize = ZstdLibrary.CStreamOutSize();
|
||||
|
||||
private final byte[] buffer = new byte[outputBufferSize];
|
||||
|
||||
private ZstdOutputStream(OutputStream sink,
|
||||
ZstdCompressionCtx ctx,
|
||||
@@ -37,7 +37,7 @@ public class ZstdOutputStream extends OutputStream {
|
||||
}
|
||||
|
||||
public static ZstdOutputStream from(OutputStream sink) {
|
||||
return from(sink, 3);
|
||||
return from(sink, 0);
|
||||
}
|
||||
|
||||
public static ZstdOutputStream from(OutputStream sink,
|
||||
@@ -49,6 +49,7 @@ public class ZstdOutputStream extends OutputStream {
|
||||
}
|
||||
ZstdCompressionCtx ctx = new ZstdCompressionCtx();
|
||||
ctx.setParameter(CompressionParameter.compressionLevel, compressionLevel);
|
||||
ctx.setParameter(CompressionParameter.checksumFlag, 1);
|
||||
return new ZstdOutputStream(sink, ctx, true);
|
||||
}
|
||||
|
||||
@@ -62,12 +63,11 @@ public class ZstdOutputStream extends OutputStream {
|
||||
input.pos = zero;
|
||||
while (true) {
|
||||
size_t rc = ZstdLibrary.compressStream2(ctx.ctx, output, input, flag);
|
||||
if (output.pos.longValue() > 0) {
|
||||
int limit = output.pos.intValue();
|
||||
while(output.dst.position() < limit) {
|
||||
byte b = output.dst.get();
|
||||
sink.write(b);
|
||||
}
|
||||
if (flag == ZSTD_EndDirective.ZSTD_e_end || output.pos.longValue() > output.dst.capacity() / 2) {
|
||||
int toWrite = output.pos.intValue() - output.dst.position();
|
||||
|
||||
output.dst.get(buffer, output.dst.position(), toWrite);
|
||||
sink.write(buffer, 0, toWrite);
|
||||
output.pos = zero;
|
||||
output.dst.position(0);
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ public class ZSTD_inBuffer extends Structure {
|
||||
public size_t pos;
|
||||
|
||||
public ZSTD_inBuffer(int size) {
|
||||
this.src = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
|
||||
this.src = ByteBuffer.allocateDirect(size);
|
||||
this.size = new size_t(this.src.capacity());
|
||||
this.pos = new size_t(this.src.capacity());
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ public class ZSTD_outBuffer extends Structure {
|
||||
public size_t pos;
|
||||
|
||||
public ZSTD_outBuffer(int size) {
|
||||
this.dst = ByteBuffer.allocateDirect(size).order(ByteOrder.nativeOrder());
|
||||
this.dst = ByteBuffer.allocateDirect(size);
|
||||
this.size = new size_t(dst.capacity());
|
||||
this.pos = new size_t(0);
|
||||
}
|
||||
|
Reference in New Issue
Block a user