77import java .util .Queue ;
88import java .util .concurrent .ConcurrentHashMap ;
99import java .util .concurrent .ConcurrentLinkedQueue ;
10+ import java .util .function .Function ;
1011
1112import org .jetbrains .annotations .Nullable ;
1213
@@ -31,24 +32,30 @@ public abstract class DrawManager<N extends AbstractInstancer<?>> {
3132
3233 /**
3334 * A map of instancer keys to instancers.
34- * <br>
35- * This map is populated as instancers are requested and contains both initialized and uninitialized instancers.
35+ *
36+ * <p> This map is populated as instancers are requested and contains both initialized and uninitialized instancers.
3637 */
3738 protected final Map <InstancerKey <?>, N > instancers = new ConcurrentHashMap <>();
3839 /**
3940 * A list of instancers that have not yet been initialized.
40- * <br>
41- * All new instancers land here before having resources allocated in {@link #render}.
41+ *
42+ * <p> All new instancers land here before having resources allocated in {@link #render}.
4243 */
4344 protected final Queue <UninitializedInstancer <N , ?>> initializationQueue = new ConcurrentLinkedQueue <>();
4445
46+ /**
47+ * Function object to pass into computeIfAbsent.
48+ * <p>Create once and cache to avoid allocating every time.
49+ */
50+ protected final Function <InstancerKey <?>, N > createAndDeferInit = this ::createAndDeferInit ;
51+
4552 public <I extends Instance > AbstractInstancer <I > getInstancer (Environment environment , InstanceType <I > type , Model model , int bias ) {
4653 return getInstancer (new InstancerKey <>(environment , type , model , bias ));
4754 }
4855
4956 @ SuppressWarnings ("unchecked" )
5057 public <I extends Instance > AbstractInstancer <I > getInstancer (InstancerKey <I > key ) {
51- return (AbstractInstancer <I >) instancers .computeIfAbsent (key , this :: createAndDeferInit );
58+ return (AbstractInstancer <I >) instancers .computeIfAbsent (key , createAndDeferInit );
5259 }
5360
5461 public Plan <RenderContext > createFramePlan () {
0 commit comments