Replace google guava with lighter library for a specific map implementation.

This commit is contained in:
Marc Baloup 2024-07-27 17:41:21 +02:00
parent 3e6cf96040
commit 4be37945cb
3 changed files with 36 additions and 7 deletions

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
/.idea /.idea
/*/target /*/target
dependency-reduced-pom.xml dependency-reduced-pom.xml
*.iml

View File

@ -25,9 +25,9 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>org.plumelib</groupId>
<artifactId>guava</artifactId> <artifactId>hashmap-util</artifactId>
<version>32.1.2-jre</version> <!-- Match the version imported by Paper API/BungeeCord API if possible --> <version>0.0.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
@ -47,6 +47,7 @@
<artifactSet> <artifactSet>
<includes> <includes>
<include>io.github.classgraph:classgraph</include> <include>io.github.classgraph:classgraph</include>
<include>org.plumelib:*</include>
</includes> </includes>
</artifactSet> </artifactSet>
<filters> <filters>
@ -60,6 +61,26 @@
<exclude>META-INF/MANIFEST.MF</exclude> <exclude>META-INF/MANIFEST.MF</exclude>
</excludes> </excludes>
</filter> </filter>
<filter>
<artifact>org.plumelib:hashmap-util</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
<filter>
<artifact>org.plumelib:reflection-util</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/MANIFEST.MF</exclude>
</excludes>
</filter>
</filters> </filters>
<relocations> <relocations>
<relocation> <relocation>
@ -70,6 +91,10 @@
<pattern>nonapi.io.github.classgraph</pattern> <pattern>nonapi.io.github.classgraph</pattern>
<shadedPattern>fr.pandacube.lib.reflect.shaded.classgraph.nonapi</shadedPattern> <shadedPattern>fr.pandacube.lib.reflect.shaded.classgraph.nonapi</shadedPattern>
</relocation> </relocation>
<relocation>
<pattern>org.plumelib</pattern>
<shadedPattern>fr.pandacube.lib.reflect.shaded.plumelib</shadedPattern>
</relocation>
</relocations> </relocations>
</configuration> </configuration>
</execution> </execution>

View File

@ -1,8 +1,7 @@
package fr.pandacube.lib.reflect.wrapper; package fr.pandacube.lib.reflect.wrapper;
import com.google.common.collect.MapMaker;
import fr.pandacube.lib.reflect.ReflectConstructor; import fr.pandacube.lib.reflect.ReflectConstructor;
import org.plumelib.util.WeakIdentityHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -17,7 +16,10 @@ import static fr.pandacube.lib.util.ThrowableUtil.wrapEx;
public abstract class ReflectWrapper implements ReflectWrapperI { public abstract class ReflectWrapper implements ReflectWrapperI {
private static final Map<Object, ReflectWrapperI> objectWrapperCache = new MapMaker().weakKeys().makeMap(); private static final Map<Object, ReflectWrapperI> objectWrapperCache = new WeakIdentityHashMap<>();
/*
* WeakHashMap is not suitable because we want the keys to be compared by reference (==) and not by the .equals() method.
*/
/** /**
* Unwraps the object from the provided reflect wrapper. * Unwraps the object from the provided reflect wrapper.