3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-05 02:50:05 +01:00

Use unsynchronized buffered OutputStream for history (#2127)

* Use unsychronized buffered OutputStream

* Add note

* Avoid synchronization on DataOutputStream#write
Dieser Commit ist enthalten in:
Hannes Greule 2023-03-06 13:54:35 +01:00 committet von GitHub
Ursprung 211e8034ff
Commit 8a3052683e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 13 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,13 @@ public class FaweOutputStream extends DataOutputStream {
return parent;
}
// overwritten to un-synchronized
@Override
public void write(final int b) throws IOException {
out.write(b);
written++;
}
public void write(int b, int amount) throws IOException {
for (int i = 0; i < amount; i++) {
write(b);

Datei anzeigen

@ -27,6 +27,7 @@ import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.Component;
import it.unimi.dsi.fastutil.io.FastBufferedInputStream;
import it.unimi.dsi.fastutil.io.FastBufferedOutputStream;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
import net.jpountz.lz4.LZ4Compressor;
@ -40,7 +41,6 @@ import javax.imageio.ImageIO;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -273,9 +273,12 @@ public class MainUtil {
return buffer;
}
/**
* Note: The returned stream is not thread safe.
*/
public static FaweOutputStream getCompressedOS(OutputStream os, int amount, int buffer) throws IOException {
os.write((byte) 10 + amount);
os = new BufferedOutputStream(os, buffer);
os = new FastBufferedOutputStream(os, buffer);
if (amount == 0) {
return new FaweOutputStream(os);
}
@ -296,7 +299,7 @@ public class MainUtil {
os = new LZ4BlockOutputStream(os, buffer, factory.highCompressor());
}
}
os = new BufferedOutputStream(os, buffer);
os = new FastBufferedOutputStream(os, buffer);
return new FaweOutputStream(os);
}