From f7c4320b7f8e137b4c05f73715f9609b74f4d117 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Tue, 20 Dec 2022 11:18:33 +0000 Subject: [PATCH] [1.18.x] Make Util.memoize thread-safe (#9166) * Make Util.memoize thread-safe * Add the forge marker present in the PR --- patches/minecraft/net/minecraft/Util.java.patch | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/patches/minecraft/net/minecraft/Util.java.patch b/patches/minecraft/net/minecraft/Util.java.patch index 8dac1a5ae7..ddd797ed46 100644 --- a/patches/minecraft/net/minecraft/Util.java.patch +++ b/patches/minecraft/net/minecraft/Util.java.patch @@ -19,3 +19,13 @@ if (SharedConstants.f_136183_) { throw illegalargumentexception; } +@@ -649,7 +_,8 @@ + + public static Function m_143827_(final Function p_143828_) { + return new Function() { +- private final Map f_143852_ = Maps.newHashMap(); ++ // FORGE: Allow using memoized functions from multiple threads. ++ private final Map f_143852_ = Maps.newConcurrentMap(); + + public R apply(T p_211578_) { + return this.f_143852_.computeIfAbsent(p_211578_, p_143828_);