mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
227 lines
12 KiB
Diff
227 lines
12 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 ba20e87d2105ce53cdaf4049de2388d05fcd1b56..35b5eb517fd8b25e5f755c18f666339a4a09badc 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 6fbb131b472a3093b137d8ced9889777a133bd5b..9372cdd6cef64c8b5019e3f73d7d8512caed0c60 100644
|
|
--- a/net/minecraft/nbt/ByteArrayTag.java
|
|
+++ b/net/minecraft/nbt/ByteArrayTag.java
|
|
@@ -144,7 +144,7 @@ public final class ByteArrayTag implements CollectionTag {
|
|
|
|
@Override
|
|
public void clear() {
|
|
- this.data = new byte[0];
|
|
+ this.data = org.leavesmc.leaves.util.ArrayConstants.emptyByteArray; // Leaves - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/nbt/IntArrayTag.java b/net/minecraft/nbt/IntArrayTag.java
|
|
index a8ea2aeb5a02903a37376fb78b49c10745147411..9b9cc3821f30380d095a8c4b11a246fb2b648df7 100644
|
|
--- a/net/minecraft/nbt/IntArrayTag.java
|
|
+++ b/net/minecraft/nbt/IntArrayTag.java
|
|
@@ -151,7 +151,7 @@ public final class IntArrayTag implements CollectionTag {
|
|
|
|
@Override
|
|
public void clear() {
|
|
- this.data = new int[0];
|
|
+ this.data = org.leavesmc.leaves.util.ArrayConstants.emptyIntArray; // Leaves - reduce array allocations
|
|
}
|
|
|
|
@Override
|
|
diff --git a/net/minecraft/network/Connection.java b/net/minecraft/network/Connection.java
|
|
index 7af8b2cf9ccfeadac1cc60541da31ba6f4dc0edb..284cdbd6034ec8962409abba6da37eab311018cc 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 a2199f7aac4f44a70087dd90fe9330fcb8970772..11cd457958e2643549f0d8786dfbf8711cdc9a87 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -165,6 +165,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 655ca2ead22addbb458b89e12cb2be1d269e4f5e..926b09363bf5c8555a27e4be0374a5a0d3ee0c0d 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -236,6 +236,7 @@ import org.bukkit.event.player.PlayerToggleFlightEvent;
|
|
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
|
import org.bukkit.event.player.PlayerToggleSprintEvent;
|
|
// CraftBukkit end
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public class ServerGamePacketListenerImpl
|
|
extends ServerCommonPacketListenerImpl
|
|
@@ -796,7 +797,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 7950f4f88d8a83ed5610b7af4e134557d32da3f0..07342673c333436fc3f4779ffcfa0a451bd524dd 100644
|
|
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
@@ -49,6 +49,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 7c13e7b7a547150642c4a4bddf5e8dee1d580984..21d50e9a60be430d8fff259d31793c5a897d2272 100644
|
|
--- a/net/minecraft/world/level/Level.java
|
|
+++ b/net/minecraft/world/level/Level.java
|
|
@@ -93,6 +93,7 @@ import org.bukkit.craftbukkit.block.CraftBlockState;
|
|
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
|
import org.bukkit.entity.SpawnCategory;
|
|
// CraftBukkit end
|
|
+import org.leavesmc.leaves.util.ArrayConstants;
|
|
|
|
public abstract class Level implements LevelAccessor, UUIDLookup<Entity>, 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 a647d76d365a60b95a3eb7927ac426bf70d417f3..056a88405be08bf6acd5c94b6f9d042b15a1ba0a 100644
|
|
--- a/net/minecraft/world/level/block/ComposterBlock.java
|
|
+++ b/net/minecraft/world/level/block/ComposterBlock.java
|
|
@@ -419,7 +419,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
|
|
@@ -454,7 +454,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
|
|
@@ -505,7 +505,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 78b3bdb668320e9cf2fb09b59929fac43cf56aca..f1f3c52a147165881de76b1f94ef57cfc9142a2a 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;
|