mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
282 lines
14 KiB
Diff
282 lines
14 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
Date: Thu, 20 Jul 2023 15:03:28 +0800
|
|
Subject: [PATCH] Reduce array allocations
|
|
|
|
This patch is Powered by Gale(https://github.com/GaleMC/Gale)
|
|
|
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
|
index d21ce54ebb5724c04eadf56a2cde701d5eeb5db2..fa4b8ea36acf031ceafc1812e657c2312eb49599 100644
|
|
--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
|
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
|
|
@@ -29,6 +29,7 @@ import java.util.Arrays;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.function.Predicate;
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public final class ChunkEntitySlices {
|
|
|
|
@@ -378,7 +379,7 @@ public final class ChunkEntitySlices {
|
|
|
|
private static final class BasicEntityList<E extends Entity> {
|
|
|
|
- private static final Entity[] EMPTY = new Entity[0];
|
|
+ // protected static final Entity[] EMPTY = new Entity[0]; // Leaves - reduce array allocations
|
|
private static final int DEFAULT_CAPACITY = 4;
|
|
|
|
private E[] storage;
|
|
@@ -389,7 +390,7 @@ public final class ChunkEntitySlices {
|
|
}
|
|
|
|
public BasicEntityList(final int cap) {
|
|
- this.storage = (E[])(cap <= 0 ? EMPTY : new Entity[cap]);
|
|
+ this.storage = (E[])(cap <= 0 ? ArrayConstants.emptyEntityArray : new Entity[cap]); // Leaves - reduce array allocations
|
|
}
|
|
|
|
public boolean isEmpty() {
|
|
@@ -401,7 +402,7 @@ public final class ChunkEntitySlices {
|
|
}
|
|
|
|
private void resize() {
|
|
- if (this.storage == EMPTY) {
|
|
+ if (this.storage == ArrayConstants.emptyEntityArray) { // Leaves - reduce array allocations
|
|
this.storage = (E[])new Entity[DEFAULT_CAPACITY];
|
|
} else {
|
|
this.storage = Arrays.copyOf(this.storage, this.storage.length * 2);
|
|
diff --git a/net/minecraft/nbt/ByteArrayTag.java b/net/minecraft/nbt/ByteArrayTag.java
|
|
index 6927124a4ea1f460158bf25679104b6f9e9ccee4..b0e8f47b9fe2b62d03c11a0b95253d7de7b8adac 100644
|
|
--- a/net/minecraft/nbt/ByteArrayTag.java
|
|
+++ b/net/minecraft/nbt/ByteArrayTag.java
|
|
@@ -6,6 +6,7 @@ import java.io.IOException;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public class ByteArrayTag extends CollectionTag<ByteTag> {
|
|
private static final int SELF_SIZE_IN_BYTES = 24;
|
|
@@ -174,7 +175,7 @@ public class ByteArrayTag extends CollectionTag<ByteTag> {
|
|
|
|
@Override
|
|
public void clear() {
|
|
- this.data = new byte[0];
|
|
+ this.data = ArrayConstants.emptyByteArray; // Leaves - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/nbt/CompoundTag.java b/net/minecraft/nbt/CompoundTag.java
|
|
index 361bc458e0bb590c43da60a1cd993a2785ee45e9..9d1e0ba4ecccfc8a251d440d63ed90796981808e 100644
|
|
--- a/net/minecraft/nbt/CompoundTag.java
|
|
+++ b/net/minecraft/nbt/CompoundTag.java
|
|
@@ -18,6 +18,7 @@ import javax.annotation.Nullable;
|
|
import net.minecraft.CrashReport;
|
|
import net.minecraft.CrashReportCategory;
|
|
import net.minecraft.ReportedException;
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public class CompoundTag implements Tag {
|
|
public static final Codec<CompoundTag> CODEC = Codec.PASSTHROUGH
|
|
@@ -409,7 +410,7 @@ public class CompoundTag implements Tag {
|
|
throw new ReportedException(this.createReport(key, ByteArrayTag.TYPE, var3));
|
|
}
|
|
|
|
- return new byte[0];
|
|
+ return ArrayConstants.emptyByteArray; // Leaves - reduce array allocations
|
|
}
|
|
|
|
public int[] getIntArray(String key) {
|
|
@@ -421,7 +422,7 @@ public class CompoundTag implements Tag {
|
|
throw new ReportedException(this.createReport(key, IntArrayTag.TYPE, var3));
|
|
}
|
|
|
|
- return new int[0];
|
|
+ return ArrayConstants.emptyIntArray; // Leaves - reduce array allocations
|
|
}
|
|
|
|
public long[] getLongArray(String key) {
|
|
@@ -433,7 +434,7 @@ public class CompoundTag implements Tag {
|
|
throw new ReportedException(this.createReport(key, LongArrayTag.TYPE, var3));
|
|
}
|
|
|
|
- return new long[0];
|
|
+ return ArrayConstants.emptyLongArray; // Leaves - reduce array allocations
|
|
}
|
|
|
|
public CompoundTag getCompound(String key) {
|
|
diff --git a/net/minecraft/nbt/IntArrayTag.java b/net/minecraft/nbt/IntArrayTag.java
|
|
index 7e27546bcb587d03b6de2ab43244e6c61fdb55f4..9e94f41e61687e2dacafec9c06646ec7f7980b62 100644
|
|
--- a/net/minecraft/nbt/IntArrayTag.java
|
|
+++ b/net/minecraft/nbt/IntArrayTag.java
|
|
@@ -6,6 +6,7 @@ import java.io.IOException;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public class IntArrayTag extends CollectionTag<IntTag> {
|
|
private static final int SELF_SIZE_IN_BYTES = 24;
|
|
@@ -181,7 +182,7 @@ public class IntArrayTag extends CollectionTag<IntTag> {
|
|
|
|
@Override
|
|
public void clear() {
|
|
- this.data = new int[0];
|
|
+ this.data = ArrayConstants.emptyIntArray; // Leaves - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
|
|
index 364ddf9f25ef3cb97ba788c469fee9dd495b84a7..fd490f139e901c2ac598f1eab7aa8d50c65ef864 100644
|
|
--- a/net/minecraft/network/Connection.java
|
|
+++ b/net/minecraft/network/Connection.java
|
|
@@ -65,6 +65,7 @@ import org.apache.commons.lang3.Validate;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Marker;
|
|
import org.slf4j.MarkerFactory;
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
private static final float AVERAGE_PACKETS_SMOOTHING = 0.75F;
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index 88a4ddf7dd3cfeef3c86406a053627d73b5db654..73e0119c4b6f81d08bdfe93751c904962701bfec 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -169,6 +169,7 @@ import net.minecraft.world.phys.shapes.Shapes;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraft.world.ticks.LevelTicks;
|
|
import org.slf4j.Logger;
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLevel, ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemServerLevel, ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemLevelReader, ca.spottedleaf.moonrise.patches.chunk_tick_iteration.ChunkTickServerLevel { // Paper - rewrite chunk system // Paper - chunk tick iteration
|
|
public static final BlockPos END_SPAWN_POINT = new BlockPos(100, 50, 0);
|
|
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index 491ebf1bf1729fc673a824866005cbd995fe4ac5..ded11128912f99b592285e72007f1379d1b5ea09 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -245,6 +245,7 @@ import org.bukkit.inventory.CraftingInventory;
|
|
import org.bukkit.inventory.InventoryView;
|
|
import org.bukkit.inventory.SmithingInventory;
|
|
// CraftBukkit end
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public class ServerGamePacketListenerImpl
|
|
extends ServerCommonPacketListenerImpl
|
|
@@ -804,7 +805,7 @@ public class ServerGamePacketListenerImpl
|
|
// Paper start
|
|
final int index;
|
|
if (packet.getCommand().length() > 64 && ((index = packet.getCommand().indexOf(' ')) == -1 || index >= 64)) {
|
|
- this.disconnectAsync(Component.translatable("disconnect.spam"), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - add proper async disconnect
|
|
+ this.disconnectAsync(Component.translatable("disconnect.spam", ArrayConstants.emptyObjectArray), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM); // Paper - add proper async disconnect // Leaves - reduce array allocations
|
|
return;
|
|
}
|
|
// Paper end
|
|
diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
index 6689aeacf50d1498e8d23cce696fb4fecbd1cf39..66d74f720f60c85d3b0e0c04e45bbceedc4e314a 100644
|
|
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
@@ -50,6 +50,7 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
|
|
import org.bukkit.craftbukkit.util.Waitable;
|
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
|
import org.bukkit.event.player.PlayerPreLoginEvent;
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, TickablePacketListener, CraftPlayer.TransferCookieConnection {
|
|
// CraftBukkit end
|
|
diff --git a/net/minecraft/server/players/StoredUserList.java b/net/minecraft/server/players/StoredUserList.java
|
|
index d445e8f126f077d8419c52fa5436ea963a1a42a4..0c0f70b5c624e05811aef398a2e6c29c14a9e323 100644
|
|
--- a/net/minecraft/server/players/StoredUserList.java
|
|
+++ b/net/minecraft/server/players/StoredUserList.java
|
|
@@ -21,6 +21,7 @@ import javax.annotation.Nullable;
|
|
import net.minecraft.Util;
|
|
import net.minecraft.util.GsonHelper;
|
|
import org.slf4j.Logger;
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
@@ -70,7 +71,7 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
}
|
|
|
|
public String[] getUserList() {
|
|
- return this.map.keySet().toArray(new String[0]);
|
|
+ return (String[]) this.map.keySet().toArray(ArrayConstants.emptyStringArray); // Leaves - reduce array allocations
|
|
}
|
|
|
|
public boolean isEmpty() {
|
|
diff --git a/net/minecraft/util/ZeroBitStorage.java b/net/minecraft/util/ZeroBitStorage.java
|
|
index 50993ce7519a77c6a9d36cb925125adccda7037f..e5124b566e791c1c011b301f910a892689cf3c65 100644
|
|
--- a/net/minecraft/util/ZeroBitStorage.java
|
|
+++ b/net/minecraft/util/ZeroBitStorage.java
|
|
@@ -5,7 +5,7 @@ import java.util.function.IntConsumer;
|
|
import org.apache.commons.lang3.Validate;
|
|
|
|
public class ZeroBitStorage implements BitStorage {
|
|
- public static final long[] RAW = new long[0];
|
|
+ public static final long[] RAW = org.leavesmc.leaves.util.ArrayConstants.emptyLongArray; // Leaves - reduce array allocations
|
|
private final int size;
|
|
|
|
public ZeroBitStorage(int size) {
|
|
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
|
|
index e9ec19be9393ccd1e257247de86ba05e51471790..e10f4190393a934d617cd2c7afd05f3a4a6e89f9 100644
|
|
--- a/net/minecraft/world/level/Level.java
|
|
+++ b/net/minecraft/world/level/Level.java
|
|
@@ -102,6 +102,7 @@ import org.bukkit.craftbukkit.util.CraftSpawnCategory;
|
|
import org.bukkit.entity.SpawnCategory;
|
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
|
// CraftBukkit end
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedleaf.moonrise.patches.chunk_system.level.ChunkSystemLevel, ca.spottedleaf.moonrise.patches.chunk_system.world.ChunkSystemEntityGetter { // Paper - rewrite chunk system // Paper - optimise collisions
|
|
public static final Codec<ResourceKey<Level>> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION);
|
|
diff --git a/net/minecraft/world/level/block/ComposterBlock.java b/net/minecraft/world/level/block/ComposterBlock.java
|
|
index 86f9c284f434a16888beb60b89f460de2c0450a8..e3177018adab3d87eb4af8ac158def96908b041a 100644
|
|
--- a/net/minecraft/world/level/block/ComposterBlock.java
|
|
+++ b/net/minecraft/world/level/block/ComposterBlock.java
|
|
@@ -410,7 +410,7 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
|
|
@Override
|
|
public int[] getSlotsForFace(Direction side) {
|
|
- return new int[0];
|
|
+ return org.leavesmc.leaves.util.ArrayConstants.emptyIntArray; // Leaves - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
@@ -445,7 +445,7 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
|
|
@Override
|
|
public int[] getSlotsForFace(Direction side) {
|
|
- return side == Direction.UP ? new int[]{0} : new int[0];
|
|
+ return side == Direction.UP ? org.leavesmc.leaves.util.ArrayConstants.zeroSingletonIntArray : org.leavesmc.leaves.util.ArrayConstants.emptyIntArray; // Leaves - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
@@ -496,7 +496,7 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder {
|
|
|
|
@Override
|
|
public int[] getSlotsForFace(Direction side) {
|
|
- return side == Direction.DOWN ? new int[]{0} : new int[0];
|
|
+ return side == Direction.DOWN ? org.leavesmc.leaves.util.ArrayConstants.zeroSingletonIntArray : org.leavesmc.leaves.util.ArrayConstants.emptyIntArray; // Leaves - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
index 2f5fa4310f475ecbb29e69c0461c7d3276f8536d..304940047eee6fab5b763ce13fdd5d7e6f8e70f1 100644
|
|
--- a/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
+++ b/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
@@ -38,13 +38,14 @@ import net.minecraft.world.level.block.AbstractFurnaceBlock;
|
|
import net.minecraft.world.level.block.Blocks;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.phys.Vec3;
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntity implements WorldlyContainer, RecipeCraftingHolder, StackedContentsCompatible {
|
|
protected static final int SLOT_INPUT = 0;
|
|
protected static final int SLOT_FUEL = 1;
|
|
protected static final int SLOT_RESULT = 2;
|
|
public static final int DATA_LIT_TIME = 0;
|
|
- private static final int[] SLOTS_FOR_UP = new int[]{0};
|
|
+ private static final int[] SLOTS_FOR_UP = ArrayConstants.zeroSingletonIntArray; // Leaves - reduce array allocations
|
|
private static final int[] SLOTS_FOR_DOWN = new int[]{2, 1};
|
|
private static final int[] SLOTS_FOR_SIDES = new int[]{1};
|
|
public static final int DATA_LIT_DURATION = 1;
|