[1.18.x] Make Util.memoize thread-safe (#9166)

* Make Util.memoize thread-safe

* Add the forge marker present in the PR
This commit is contained in:
Jonathan Coates authored and GitHub committed 2022-12-20 21:48:33 +10:30
1 parent 84b1a40fe2
commit f7c4320b7f
1 file changed
+10
@@ -19,3 +19,13 @@
if (SharedConstants.f_136183_) {
throw illegalargumentexception;
}
@@ -649,7 +_,8 @@
public static <T, R> Function<T, R> m_143827_(final Function<T, R> p_143828_) {
return new Function<T, R>() {
- private final Map<T, R> f_143852_ = Maps.newHashMap();
+ // FORGE: Allow using memoized functions from multiple threads.
+ private final Map<T, R> f_143852_ = Maps.newConcurrentMap();
public R apply(T p_211578_) {
return this.f_143852_.computeIfAbsent(p_211578_, p_143828_);