Skip to content

Commit 73f7061

Browse files
committed
Merge 1.20 into 1.20.4
2 parents 50556ab + 0e48559 commit 73f7061

File tree

2 files changed

+36
-26
lines changed

2 files changed

+36
-26
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.embeddedt.modernfix.common.mixin.perf.ticking_chunk_alloc;
2+
3+
import net.minecraft.world.level.chunk.ChunkAccess;
4+
import org.spongepowered.asm.mixin.Final;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.Overwrite;
7+
import org.spongepowered.asm.mixin.Shadow;
8+
9+
import java.util.Collections;
10+
import java.util.Map;
11+
12+
@Mixin(value = ChunkAccess.class, priority = 800)
13+
public class ChunkAccessMixin {
14+
@Shadow @Final private Map<?, ?> structuresRefences;
15+
private Map<?, ?> mfix$structureRefsView;
16+
17+
/**
18+
* @author embeddedt
19+
* @reason Cache returned map view to avoid allocations, return empty map when possible
20+
* so that iterator() calls don't allocate
21+
* <p></p>
22+
* Note: technically, this introduces an API change, as the return value may no longer be a live view
23+
* of the structure references of the chunk. It's unlikely this will affect anything in practice.
24+
*/
25+
@Overwrite
26+
public Map<?, ?> getAllReferences() {
27+
if(this.structuresRefences.isEmpty()) {
28+
return Collections.emptyMap();
29+
}
30+
Map<?, ?> view = this.mfix$structureRefsView;
31+
if(view == null) {
32+
this.mfix$structureRefsView = view = Collections.unmodifiableMap(this.structuresRefences);
33+
}
34+
return view;
35+
}
36+
}

common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/ticking_chunk_alloc/ChunkGeneratorMixin.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)