mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
Remove CFI redirect and other minor changes.
This commit is contained in:
@ -13,6 +13,7 @@ import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
/**
|
||||
@ -83,13 +84,12 @@ public class SoftHashMap<K, V> implements Map<K, V> {
|
||||
* elements retained after a GC due to the strong references.
|
||||
* <p/>
|
||||
* Note that in a highly concurrent environments the exact total number of strong references may differ slightly
|
||||
* than the actual <code>retentionSize</code> value. This number is intended to be a best-effort retention low
|
||||
* than the actual {@code retentionSize} value. This number is intended to be a best-effort retention low
|
||||
* water mark.
|
||||
*
|
||||
* @param retentionSize the total number of most recent entries in the map that will be strongly referenced
|
||||
* (retained), preventing them from being eagerly garbage collected by the JVM.
|
||||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public SoftHashMap(int retentionSize) {
|
||||
super();
|
||||
RETENTION_SIZE = Math.max(0, retentionSize);
|
||||
@ -120,7 +120,7 @@ public class SoftHashMap<K, V> implements Map<K, V> {
|
||||
* elements retained after a GC due to the strong references.
|
||||
* <p/>
|
||||
* Note that in a highly concurrent environments the exact total number of strong references may differ slightly
|
||||
* than the actual <code>retentionSize</code> value. This number is intended to be a best-effort retention low
|
||||
* than the actual {@code retentionSize} value. This number is intended to be a best-effort retention low
|
||||
* water mark.
|
||||
*
|
||||
* @param source the backing map to populate this {@code SoftHashMap}
|
||||
@ -132,6 +132,7 @@ public class SoftHashMap<K, V> implements Map<K, V> {
|
||||
putAll(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
processQueue();
|
||||
|
||||
@ -185,24 +186,28 @@ public class SoftHashMap<K, V> implements Map<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
processQueue();
|
||||
return map.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
processQueue();
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
processQueue();
|
||||
Collection values = values();
|
||||
return values != null && values.contains(value);
|
||||
Collection<?> values = values();
|
||||
return values.contains(value);
|
||||
}
|
||||
|
||||
public void putAll(Map<? extends K, ? extends V> m) {
|
||||
if (m == null || m.isEmpty()) {
|
||||
@Override
|
||||
public void putAll(@NotNull Map<? extends K, ? extends V> m) {
|
||||
if (m.isEmpty()) {
|
||||
processQueue();
|
||||
return;
|
||||
}
|
||||
@ -211,17 +216,21 @@ public class SoftHashMap<K, V> implements Map<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<K> keySet() {
|
||||
processQueue();
|
||||
return map.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<V> values() {
|
||||
processQueue();
|
||||
Collection<K> keys = map.keySet();
|
||||
if (keys.isEmpty()) {
|
||||
//noinspection unchecked
|
||||
return Collections.EMPTY_SET;
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Collection<V> values = new ArrayList<>(keys.size());
|
||||
for (K key : keys) {
|
||||
@ -236,6 +245,7 @@ public class SoftHashMap<K, V> implements Map<K, V> {
|
||||
/**
|
||||
* Creates a new entry, but wraps the value in a SoftValue instance to enable auto garbage collection.
|
||||
*/
|
||||
@Override
|
||||
public V put(K key, V value) {
|
||||
processQueue(); // throw out garbage collected values first
|
||||
SoftValue<V, K> sv = new SoftValue<>(value, key, queue);
|
||||
@ -244,12 +254,14 @@ public class SoftHashMap<K, V> implements Map<K, V> {
|
||||
return previous != null ? previous.get() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V remove(Object key) {
|
||||
processQueue(); // throw out garbage collected values first
|
||||
SoftValue<V, K> raw = map.remove(key);
|
||||
return raw != null ? raw.get() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
strongReferencesLock.lock();
|
||||
try {
|
||||
@ -261,17 +273,20 @@ public class SoftHashMap<K, V> implements Map<K, V> {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
processQueue(); // throw out garbage collected values first
|
||||
return map.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Set<Map.Entry<K, V>> entrySet() {
|
||||
processQueue(); // throw out garbage collected values first
|
||||
Collection<K> keys = map.keySet();
|
||||
if (keys.isEmpty()) {
|
||||
//noinspection unchecked
|
||||
return Collections.EMPTY_SET;
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
Map<K, V> kvPairs = new HashMap<>(keys.size());
|
||||
|
@ -80,7 +80,7 @@ public class ReflectionUtils {
|
||||
blankField(enumClass, "enumConstants"); // IBM JDK
|
||||
}
|
||||
|
||||
private static Class<?> UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.EMPTY_MAP).getClass();
|
||||
private static Class<?> UNMODIFIABLE_MAP = Collections.unmodifiableMap(Collections.emptyMap()).getClass();
|
||||
|
||||
public static <T, V> Map<T, V> getMap(Map<T, V> map) {
|
||||
try {
|
||||
|
@ -12,6 +12,8 @@ package net.jpountz.lz4;
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file has been modified for use in the FAWE project.
|
||||
*/
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
@ -21,10 +23,10 @@ import java.util.zip.Checksum;
|
||||
import net.jpountz.util.SafeUtils;
|
||||
|
||||
/**
|
||||
* Streaming LZ4.
|
||||
* <p>
|
||||
* Streaming LZ4 (not compatible with the LZ4 Frame format).
|
||||
* This class compresses data into fixed-size blocks of compressed data.
|
||||
*
|
||||
* This class uses its own format and is not compatible with the LZ4 Frame format.
|
||||
|
||||
* @see LZ4BlockInputStream
|
||||
*/
|
||||
public final class LZ4BlockOutputStream extends FilterOutputStream {
|
||||
@ -73,17 +75,17 @@ public final class LZ4BlockOutputStream extends FilterOutputStream {
|
||||
private int o;
|
||||
|
||||
/**
|
||||
* Create a new {@link OutputStream} with configurable block size. Large
|
||||
* Creates a new {@link OutputStream} with configurable block size. Large
|
||||
* blocks require more memory at compression and decompression time but
|
||||
* should improve the compression ratio.
|
||||
*
|
||||
* @param out the {@link OutputStream} to feed
|
||||
* @param blockSize the maximum number of bytes to try to compress at once,
|
||||
* must be >= 64 and <= 32 M
|
||||
* must be >= 64 and <= 32 M
|
||||
* @param compressor the {@link LZ4Compressor} instance to use to compress
|
||||
* data
|
||||
* data
|
||||
* @param checksum the {@link Checksum} instance to use to check data for
|
||||
* integrity.
|
||||
* integrity.
|
||||
* @param syncFlush true if pending data should also be flushed on {@link #flush()}
|
||||
*/
|
||||
public LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor, Checksum checksum, boolean syncFlush) {
|
||||
@ -101,14 +103,29 @@ public final class LZ4BlockOutputStream extends FilterOutputStream {
|
||||
System.arraycopy(MAGIC, 0, compressedBuffer, 0, MAGIC_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance which checks stream integrity and doesn't sync flush.
|
||||
*
|
||||
* @param out the {@link OutputStream} to feed
|
||||
* @param blockSize the maximum number of bytes to try to compress at once,
|
||||
* must be >= 64 and <= 32 M
|
||||
* @param compressor the {@link LZ4Compressor} instance to use to compress
|
||||
* data
|
||||
*
|
||||
* @see #LZ4BlockOutputStream(OutputStream, int, LZ4Compressor, Checksum, boolean)
|
||||
*/
|
||||
public LZ4BlockOutputStream(OutputStream out, int blockSize, LZ4Compressor compressor) {
|
||||
this(out, blockSize, compressor, null, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance which compresses with the standard LZ4 compression
|
||||
* Creates a new instance which compresses with the standard LZ4 compression
|
||||
* algorithm.
|
||||
*
|
||||
* @param out the {@link OutputStream} to feed
|
||||
* @param blockSize the maximum number of bytes to try to compress at once,
|
||||
* must be >= 64 and <= 32 M
|
||||
*
|
||||
* @see #LZ4BlockOutputStream(OutputStream, int, LZ4Compressor)
|
||||
* @see LZ4Factory#fastCompressor()
|
||||
*/
|
||||
@ -117,7 +134,9 @@ public final class LZ4BlockOutputStream extends FilterOutputStream {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance which compresses into blocks of 64 KB.
|
||||
* Creates a new instance which compresses into blocks of 64 KB.
|
||||
*
|
||||
* @param out the {@link OutputStream} to feed
|
||||
*
|
||||
* @see #LZ4BlockOutputStream(OutputStream, int)
|
||||
*/
|
||||
@ -206,8 +225,8 @@ public final class LZ4BlockOutputStream extends FilterOutputStream {
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush this compressed {@link OutputStream}.
|
||||
* <p>
|
||||
* Flushes this compressed {@link OutputStream}.
|
||||
*
|
||||
* If the stream has been created with <code>syncFlush=true</code>, pending
|
||||
* data will be compressed and appended to the underlying {@link OutputStream}
|
||||
* before calling {@link OutputStream#flush()} on the underlying stream.
|
||||
@ -228,6 +247,8 @@ public final class LZ4BlockOutputStream extends FilterOutputStream {
|
||||
/**
|
||||
* Same as {@link #close()} except that it doesn't close the underlying stream.
|
||||
* This can be useful if you want to keep on using the underlying stream.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public void finish() throws IOException {
|
||||
ensureNotFinished();
|
||||
@ -255,4 +276,4 @@ public final class LZ4BlockOutputStream extends FilterOutputStream {
|
||||
+ ", compressor=" + compressor + ", checksum=" + checksum + ")";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user