PaperMC/patches/server/0323-Optimize-Captured-TileEntity-Lookup.patch

31 lines
1.7 KiB
Diff
Raw Normal View History

2021-06-13 13:40:34 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 6 Apr 2019 10:16:48 -0400
Subject: [PATCH] Optimize Captured TileEntity Lookup
upstream was doing a containsKey/get pattern, and always doing it at that.
that scenario is only even valid if were in the middle of a block place.
Optimize to check if the captured list even has values in it, and also to
just do a get call since the value can never be null.
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
2021-07-07 08:52:40 +02:00
index 0b62b8ef775a774799a56205a97f6d9a6defb583..af0dd46e352115d1984f07fff746c7ad41486ac2 100644
2021-06-13 13:40:34 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2021-07-07 08:52:40 +02:00
@@ -875,9 +875,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-13 13:40:34 +02:00
@Nullable
public BlockEntity getTileEntity(BlockPos blockposition, boolean validate) {
- if (this.capturedTileEntities.containsKey(blockposition)) {
- return this.capturedTileEntities.get(blockposition);
+ // Paper start - Optimize capturedTileEntities lookup
+ net.minecraft.world.level.block.entity.BlockEntity blockEntity;
+ if (!this.capturedTileEntities.isEmpty() && (blockEntity = this.capturedTileEntities.get(blockposition)) != null) {
+ return blockEntity;
}
+ // Paper end
// CraftBukkit end
return this.isOutsideBuildHeight(blockposition) ? null : (!this.isClientSide && Thread.currentThread() != this.thread ? null : this.getChunkAt(blockposition).getBlockEntity(blockposition, LevelChunk.EntityCreationType.IMMEDIATE));
}