Skip to content

Commit

Permalink
lz4#218 add option to prefer java version in LZ4Factory.fastestInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
subes committed Apr 10, 2024
1 parent 7c931be commit 9e7b4aa
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/java/net/jpountz/lz4/LZ4Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ private static LZ4Factory instance(String impl) {
}
}

private static final boolean PREFER_NATIVE;
private static LZ4Factory NATIVE_INSTANCE,
JAVA_UNSAFE_INSTANCE,
JAVA_SAFE_INSTANCE;

static {
final String preferNativeStr = System.getProperty("net.jpountz.lz4.PREFER_NATIVE");
PREFER_NATIVE = preferNativeStr == null || Boolean.valueOf(preferNativeStr);
}

/**
* Returns a {@link LZ4Factory} instance that returns compressors and
* decompressors that are native bindings to the original C library.
Expand Down Expand Up @@ -160,7 +166,7 @@ public static LZ4Factory fastestJavaInstance() {
* @return the fastest available {@link LZ4Factory} instance
*/
public static LZ4Factory fastestInstance() {
if (Native.isLoaded()
if (PREFER_NATIVE && Native.isLoaded()
|| Native.class.getClassLoader() == ClassLoader.getSystemClassLoader()) {
try {
return nativeInstance();
Expand Down

0 comments on commit 9e7b4aa

Please sign in to comment.