Update to .find(String) api in loader

This commit is contained in:
Joshua Suskalo 2023-09-21 10:39:15 -05:00
parent 0094634818
commit 36f1685718
No known key found for this signature in database
GPG key ID: 9B6BA586EFF1B9F0

View file

@ -10,6 +10,8 @@ import java.lang.foreign.*;
*/ */
public class Loader { public class Loader {
static SymbolLookup lookup = Linker.nativeLinker().defaultLookup().or(SymbolLookup.loaderLookup());
/** /**
* Loads a library from a given absolute file path. * Loads a library from a given absolute file path.
* *
@ -37,7 +39,6 @@ public class Loader {
* @param symbol The name of the symbol to load from a library. * @param symbol The name of the symbol to load from a library.
*/ */
public static MemorySegment findSymbol(String symbol) { public static MemorySegment findSymbol(String symbol) {
return Linker.nativeLinker().defaultLookup().lookup(symbol) return lookup.find(symbol).orElse(null);
.orElseGet(() -> SymbolLookup.loaderLookup().lookup(symbol).orElse(null));
} }
} }