From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Sat, 26 Nov 2022 11:25:45 +0100 Subject: [PATCH] Reduce array allocations License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) Gale - https://galemc.org This patch is based on the following patch: "reduce allocs" By: Simon Gardling As part of: JettPack (https://gitlab.com/Titaniumtown/JettPack) Licensed under: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html) diff --git a/src/main/java/com/destroystokyo/paper/util/maplist/EntityList.java b/src/main/java/com/destroystokyo/paper/util/maplist/EntityList.java index 0133ea6feb1ab88f021f66855669f58367e7420b..85f223ffe4414d1dc0653bda260d910dbb8c0f21 100644 --- a/src/main/java/com/destroystokyo/paper/util/maplist/EntityList.java +++ b/src/main/java/com/destroystokyo/paper/util/maplist/EntityList.java @@ -1,6 +1,7 @@ package com.destroystokyo.paper.util.maplist; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import me.titaniumtown.ArrayConstants; import net.minecraft.world.entity.Entity; import java.util.Arrays; import java.util.Iterator; @@ -17,9 +18,7 @@ public final class EntityList implements Iterable { this.entityToIndex.defaultReturnValue(Integer.MIN_VALUE); } - protected static final Entity[] EMPTY_LIST = new Entity[0]; - - protected Entity[] entities = EMPTY_LIST; + protected Entity[] entities = ArrayConstants.emptyEntityArray; // Gale - JettPack - reduce array allocations protected int count; public int size() { diff --git a/src/main/java/com/destroystokyo/paper/util/maplist/IBlockDataList.java b/src/main/java/com/destroystokyo/paper/util/maplist/IBlockDataList.java index 277cfd9d1e8fff5d9b5e534b75c3c5162d58b0b7..a6db66fd143db595802ac91296c607db4867db8e 100644 --- a/src/main/java/com/destroystokyo/paper/util/maplist/IBlockDataList.java +++ b/src/main/java/com/destroystokyo/paper/util/maplist/IBlockDataList.java @@ -3,6 +3,8 @@ package com.destroystokyo.paper.util.maplist; import it.unimi.dsi.fastutil.longs.LongIterator; import it.unimi.dsi.fastutil.shorts.Short2LongOpenHashMap; import java.util.Arrays; + +import me.titaniumtown.ArrayConstants; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.GlobalPalette; @@ -20,9 +22,7 @@ public final class IBlockDataList { this.map.defaultReturnValue(Long.MAX_VALUE); } - private static final long[] EMPTY_LIST = new long[0]; - - private long[] byIndex = EMPTY_LIST; + private long[] byIndex = ArrayConstants.emptyLongArray; // Gale - JettPack - reduce array allocations private int size; public static int getLocationKey(final int x, final int y, final int z) { diff --git a/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java b/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java index ae60bd96b5284d54676d8e7e4dd5d170b526ec1e..b269b9b55c10542b16af301be3f43798c82dde82 100644 --- a/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java +++ b/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java @@ -1,6 +1,7 @@ package io.papermc.paper.command.subcommands; import io.papermc.paper.command.PaperSubcommand; +import me.titaniumtown.ArrayConstants; import net.minecraft.server.MinecraftServer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -14,7 +15,7 @@ public final class VersionCommand implements PaperSubcommand { public boolean execute(final CommandSender sender, final String subCommand, final String[] args) { final @Nullable Command ver = MinecraftServer.getServer().server.getCommandMap().getCommand("version"); if (ver != null) { - ver.execute(sender, "paper", new String[0]); + ver.execute(sender, "paper", ArrayConstants.emptyStringArray); // Gale - JettPack - reduce array allocations } return true; } diff --git a/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java b/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java index 7e8dc9e8f381abfdcce2746edc93122d623622d1..66721a27cc9a373a12dffb72c4a403473377eff6 100644 --- a/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java +++ b/src/main/java/io/papermc/paper/world/ChunkEntitySlices.java @@ -2,9 +2,9 @@ package io.papermc.paper.world; import com.destroystokyo.paper.util.maplist.EntityList; import io.papermc.paper.chunk.system.entity.EntityLookup; -import io.papermc.paper.util.TickThread; import it.unimi.dsi.fastutil.objects.Reference2ObjectMap; import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; +import me.titaniumtown.ArrayConstants; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.FullChunkStatus; @@ -82,7 +82,7 @@ public final class ChunkEntitySlices { } } - return ret.toArray(new org.bukkit.entity.Entity[0]); + return ret.toArray(ArrayConstants.emptyBukkitEntityArray); // Gale - JettPack - reduce array allocations } public CompoundTag save() { @@ -303,7 +303,7 @@ public final class ChunkEntitySlices { protected static final class BasicEntityList { - protected static final Entity[] EMPTY = new Entity[0]; + //protected static final Entity[] EMPTY = new Entity[0]; // Gale - JettPack - reduce array allocations protected static final int DEFAULT_CAPACITY = 4; protected E[] storage; @@ -314,7 +314,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]); // Gale - JettPack - reduce array allocations } public boolean isEmpty() { @@ -326,7 +326,7 @@ public final class ChunkEntitySlices { } private void resize() { - if (this.storage == EMPTY) { + if (this.storage == ArrayConstants.emptyEntityArray) { // Gale - JettPack - reduce array allocations this.storage = (E[])new Entity[DEFAULT_CAPACITY]; } else { this.storage = Arrays.copyOf(this.storage, this.storage.length * 2); diff --git a/src/main/java/me/titaniumtown/ArrayConstants.java b/src/main/java/me/titaniumtown/ArrayConstants.java new file mode 100644 index 0000000000000000000000000000000000000000..bccd0127387d27f7eb7e6ce68f31a1686a008419 --- /dev/null +++ b/src/main/java/me/titaniumtown/ArrayConstants.java @@ -0,0 +1,21 @@ +// Gale - JettPack - reduce array allocations + +package me.titaniumtown; + +//import net.minecraft.server.level.ServerLevel; + +public final class ArrayConstants { + + private ArrayConstants() {} + + public static final Object[] emptyObjectArray = new Object[0]; + public static final int[] emptyIntArray = new int[0]; + public static final int[] zeroSingletonIntArray = new int[]{0}; + public static final byte[] emptyByteArray = new byte[0]; + public static final String[] emptyStringArray = new String[0]; + public static final long[] emptyLongArray = new long[0]; + public static final org.bukkit.entity.Entity[] emptyBukkitEntityArray = new org.bukkit.entity.Entity[0]; + public static final net.minecraft.world.entity.Entity[] emptyEntityArray = new net.minecraft.world.entity.Entity[0]; + //public static final ServerLevel[] emptyServerLevelArray = new ServerLevel[0]; + +} diff --git a/src/main/java/net/minecraft/nbt/ByteArrayTag.java b/src/main/java/net/minecraft/nbt/ByteArrayTag.java index 06648f9751fd8a322d0809ffebf6a544596ee1a4..b4c2fbdd56ba278560fc1c0d7e086dceb01ef06b 100644 --- a/src/main/java/net/minecraft/nbt/ByteArrayTag.java +++ b/src/main/java/net/minecraft/nbt/ByteArrayTag.java @@ -6,6 +6,8 @@ import java.io.DataOutput; import java.io.IOException; import java.util.Arrays; import java.util.List; + +import me.titaniumtown.ArrayConstants; import org.apache.commons.lang3.ArrayUtils; public class ByteArrayTag extends CollectionTag { @@ -175,7 +177,7 @@ public class ByteArrayTag extends CollectionTag { } public void clear() { - this.data = new byte[0]; + this.data = ArrayConstants.emptyByteArray; // Gale - JettPack - reduce array allocations } @Override diff --git a/src/main/java/net/minecraft/nbt/CompoundTag.java b/src/main/java/net/minecraft/nbt/CompoundTag.java index 4c8f2dbdd6e384be026ae1c890096f89fd744eb0..27f133159d3b9a128faa764e9605f690bf51ed4c 100644 --- a/src/main/java/net/minecraft/nbt/CompoundTag.java +++ b/src/main/java/net/minecraft/nbt/CompoundTag.java @@ -1,6 +1,5 @@ package net.minecraft.nbt; -import com.google.common.collect.Maps; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.Dynamic; @@ -14,6 +13,8 @@ import java.util.Objects; import java.util.Set; import java.util.UUID; import javax.annotation.Nullable; + +import me.titaniumtown.ArrayConstants; import net.minecraft.CrashReport; import net.minecraft.CrashReportCategory; import net.minecraft.ReportedException; @@ -420,7 +421,7 @@ public class CompoundTag implements Tag { throw new ReportedException(this.createReport(key, ByteArrayTag.TYPE, var3)); } - return new byte[0]; + return ArrayConstants.emptyByteArray; // Gale - JettPack - reduce array allocations } public int[] getIntArray(String key) { @@ -432,7 +433,7 @@ public class CompoundTag implements Tag { throw new ReportedException(this.createReport(key, IntArrayTag.TYPE, var3)); } - return new int[0]; + return ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations } public long[] getLongArray(String key) { @@ -444,7 +445,7 @@ public class CompoundTag implements Tag { throw new ReportedException(this.createReport(key, LongArrayTag.TYPE, var3)); } - return new long[0]; + return ArrayConstants.emptyLongArray; // Gale - JettPack - reduce array allocations } public CompoundTag getCompound(String key) { diff --git a/src/main/java/net/minecraft/nbt/IntArrayTag.java b/src/main/java/net/minecraft/nbt/IntArrayTag.java index ff13d67151c50ea11a45117e524c7524e2b1a202..3f6327661e593e52a89c247288f0104cdbd2a441 100644 --- a/src/main/java/net/minecraft/nbt/IntArrayTag.java +++ b/src/main/java/net/minecraft/nbt/IntArrayTag.java @@ -6,6 +6,8 @@ import java.io.DataOutput; import java.io.IOException; import java.util.Arrays; import java.util.List; + +import me.titaniumtown.ArrayConstants; import org.apache.commons.lang3.ArrayUtils; public class IntArrayTag extends CollectionTag { @@ -186,7 +188,7 @@ public class IntArrayTag extends CollectionTag { } public void clear() { - this.data = new int[0]; + this.data = ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations } @Override diff --git a/src/main/java/net/minecraft/nbt/ListTag.java b/src/main/java/net/minecraft/nbt/ListTag.java index c6877c7167dd5b1c61c776b0c7865d9064e69202..43e429053ca92d9ef7e9b5b9d466352b1b0a3fc8 100644 --- a/src/main/java/net/minecraft/nbt/ListTag.java +++ b/src/main/java/net/minecraft/nbt/ListTag.java @@ -2,6 +2,8 @@ package net.minecraft.nbt; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import me.titaniumtown.ArrayConstants; + import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -261,7 +263,7 @@ public class ListTag extends CollectionTag { } } - return new int[0]; + return ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations } public long[] getLongArray(int index) { @@ -272,7 +274,7 @@ public class ListTag extends CollectionTag { } } - return new long[0]; + return ArrayConstants.emptyLongArray; // Gale - JettPack - reduce array allocations } public double getDouble(int index) { diff --git a/src/main/java/net/minecraft/nbt/LongArrayTag.java b/src/main/java/net/minecraft/nbt/LongArrayTag.java index 3604e22f593275140d706c296355ee06ca8ec888..d28507d1e0b076f109c3c85b92ec0682062686c2 100644 --- a/src/main/java/net/minecraft/nbt/LongArrayTag.java +++ b/src/main/java/net/minecraft/nbt/LongArrayTag.java @@ -6,6 +6,8 @@ import java.io.DataOutput; import java.io.IOException; import java.util.Arrays; import java.util.List; + +import me.titaniumtown.ArrayConstants; import org.apache.commons.lang3.ArrayUtils; public class LongArrayTag extends CollectionTag { @@ -190,7 +192,7 @@ public class LongArrayTag extends CollectionTag { @Override public void clear() { - this.data = new long[0]; + this.data = ArrayConstants.emptyLongArray; // Gale - JettPack - reduce array allocations } @Override diff --git a/src/main/java/net/minecraft/network/CipherBase.java b/src/main/java/net/minecraft/network/CipherBase.java index a2920b8a9eff77d9c5d1d7f70ad3abdacba8f0fa..43f402d9032e4570a81a80e41221559820a0c9fd 100644 --- a/src/main/java/net/minecraft/network/CipherBase.java +++ b/src/main/java/net/minecraft/network/CipherBase.java @@ -2,13 +2,15 @@ package net.minecraft.network; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; +import me.titaniumtown.ArrayConstants; + import javax.crypto.Cipher; import javax.crypto.ShortBufferException; public class CipherBase { private final Cipher cipher; - private byte[] heapIn = new byte[0]; - private byte[] heapOut = new byte[0]; + private byte[] heapIn = ArrayConstants.emptyByteArray; // Gale - JettPack - reduce array allocations + private byte[] heapOut = ArrayConstants.emptyByteArray; // Gale - JettPack - reduce array allocations protected CipherBase(Cipher cipher) { this.cipher = cipher; diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java index 2ae08b21c63490bbf8cd870f9585d82ed131f815..79ff5a76b382581c4125b859d9f00ee19d784100 100644 --- a/src/main/java/net/minecraft/network/Connection.java +++ b/src/main/java/net/minecraft/network/Connection.java @@ -23,7 +23,6 @@ import io.netty.channel.epoll.EpollSocketChannel; import io.netty.channel.local.LocalChannel; import io.netty.channel.local.LocalServerChannel; import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.flow.FlowControlHandler; import io.netty.handler.timeout.ReadTimeoutHandler; @@ -39,6 +38,8 @@ import java.util.function.Supplier; import javax.annotation.Nullable; import javax.crypto.Cipher; import net.minecraft.SharedConstants; + +import me.titaniumtown.ArrayConstants; import net.minecraft.Util; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -321,7 +322,7 @@ public class Connection extends SimpleChannelInboundHandler> { } public void setListener(PacketListener packetListener) { - Validate.notNull(packetListener, "packetListener", new Object[0]); + Validate.notNull(packetListener, "packetListener", ArrayConstants.emptyObjectArray); // Gale - JettPack - reduce array allocations PacketFlow enumprotocoldirection = packetListener.flow(); if (enumprotocoldirection != this.receiving) { diff --git a/src/main/java/net/minecraft/network/chat/contents/TranslatableContents.java b/src/main/java/net/minecraft/network/chat/contents/TranslatableContents.java index d45e39bc009281c298f3dfae113dc87f2b3b1fbd..25f25c3e2882e11a80142d3282a020d28828edef 100644 --- a/src/main/java/net/minecraft/network/chat/contents/TranslatableContents.java +++ b/src/main/java/net/minecraft/network/chat/contents/TranslatableContents.java @@ -15,6 +15,8 @@ import java.util.function.Consumer; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.Nullable; + +import me.titaniumtown.ArrayConstants; import net.minecraft.commands.CommandSourceStack; import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; @@ -28,7 +30,7 @@ import net.minecraft.util.ExtraCodecs; import net.minecraft.world.entity.Entity; public class TranslatableContents implements ComponentContents { - public static final Object[] NO_ARGS = new Object[0]; + public static final Object[] NO_ARGS = ArrayConstants.emptyObjectArray; // Gale - JettPack - reduce array allocations private static final Codec PRIMITIVE_ARG_CODEC = ExtraCodecs.validate(ExtraCodecs.JAVA, TranslatableContents::filterAllowedArguments); private static final Codec ARG_CODEC = Codec.either(PRIMITIVE_ARG_CODEC, ComponentSerialization.CODEC).xmap((either) -> { return either.map((object) -> { diff --git a/src/main/java/net/minecraft/server/Main.java b/src/main/java/net/minecraft/server/Main.java index 7573c12a77797146c51ef2dfe4b2a636df45e21a..43ba5c26f40a9b00480198e10141275c07938994 100644 --- a/src/main/java/net/minecraft/server/Main.java +++ b/src/main/java/net/minecraft/server/Main.java @@ -87,7 +87,7 @@ public class Main { OptionSpec optionspec5 = optionparser.accepts("eraseCache"); OptionSpec optionspec6 = optionparser.accepts("safeMode", "Loads level with vanilla datapack only"); OptionSpec optionspec7 = optionparser.accepts("help").forHelp(); - OptionSpec optionspec8 = optionparser.accepts("universe").withRequiredArg().defaultsTo(".", new String[0]); + OptionSpec optionspec8 = optionparser.accepts("universe").withRequiredArg().defaultsTo(".", me.titaniumtown.ArrayConstants.emptyStringArray); // Gale - JettPack - reduce array allocations OptionSpec optionspec9 = optionparser.accepts("world").withRequiredArg(); OptionSpec optionspec10 = optionparser.accepts("port").withRequiredArg().ofType(Integer.class).defaultsTo(-1, new Integer[0]); OptionSpec optionspec11 = optionparser.accepts("serverId").withRequiredArg(); diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java index e8bb35322d3204e6a126bc6df0beed3f931dae6d..6bfa866ce2b3dab86dcbaba9fdf52737d7883925 100644 --- a/src/main/java/net/minecraft/server/level/ServerEntity.java +++ b/src/main/java/net/minecraft/server/level/ServerEntity.java @@ -329,7 +329,7 @@ public class ServerEntity { if (this.entity instanceof LivingEntity) { List> list = Lists.newArrayList(); - EquipmentSlot[] aenumitemslot = EquipmentSlot.values(); + EquipmentSlot[] aenumitemslot = EquipmentSlot.VALUES; // Gale - JettPack - reduce array allocations int i = aenumitemslot.length; for (int j = 0; j < i; ++j) { diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index b1e45275dd05d2d7ea163582354575bd0c896f8a..7d5e7545b995506ef554dbda70ec5eb8ccb24151 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java @@ -38,6 +38,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nonnull; import javax.annotation.Nullable; + +import me.titaniumtown.ArrayConstants; import net.minecraft.CrashReport; import net.minecraft.CrashReportCategory; import net.minecraft.Util; @@ -1050,7 +1052,7 @@ public class ServerLevel extends Level implements WorldGenLevel { BlockPos blockposition2 = blockposition.set(j + randomX, randomY, k + randomZ); BlockState iblockdata = com.destroystokyo.paper.util.maplist.IBlockDataList.getBlockDataFromRaw(raw); - iblockdata.randomTick(this, blockposition2, this.randomTickRandom); + iblockdata.randomTick(this, blockposition2.immutable(), this.randomTickRandom); // Gale - JettPack - reduce array allocations } // We drop the fluid tick since LAVA is ALREADY TICKED by the above method (See LiquidBlock). // TODO CHECK ON UPDATE (ping the Canadian) @@ -1356,7 +1358,7 @@ public class ServerLevel extends Level implements WorldGenLevel { public static List getCurrentlyTickingEntities() { Entity ticking = currentlyTickingEntity.get(); - List ret = java.util.Arrays.asList(ticking == null ? new Entity[0] : new Entity[] { ticking }); + List ret = java.util.Arrays.asList(ticking == null ? ArrayConstants.emptyEntityArray : new Entity[] { ticking }); // Gale - JettPack - reduce array allocations return ret; } diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java index b2c8ab298d79399b7aa19496bc22356030ae40ce..5a2b43ea98478a67ad712980ee8e6dbe98871433 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -28,6 +28,8 @@ import java.util.function.UnaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nullable; + +import me.titaniumtown.ArrayConstants; import net.minecraft.ChatFormatting; import net.minecraft.SharedConstants; import net.minecraft.Util; @@ -177,7 +179,6 @@ import net.minecraft.world.level.block.entity.CrafterBlockEntity; import net.minecraft.world.level.block.entity.JigsawBlockEntity; import net.minecraft.world.level.block.entity.SignBlockEntity; import net.minecraft.world.level.block.entity.StructureBlockEntity; -import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.BlockHitResult; @@ -227,8 +228,6 @@ import org.bukkit.event.inventory.InventoryCreativeEvent; import org.bukkit.event.inventory.InventoryType.SlotType; import org.bukkit.event.inventory.SmithItemEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; -import org.bukkit.event.player.PlayerAnimationEvent; -import org.bukkit.event.player.PlayerAnimationType; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; @@ -775,13 +774,13 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl // PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel()); // Paper - run this async // CraftBukkit start if (this.chatSpamTickCount.addAndGet(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamIncrement) > io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.tabSpamLimit && !this.server.getPlayerList().isOp(this.player.getGameProfile())) { // Paper start - split and make configurable - server.scheduleOnMain(() -> this.disconnect(Component.translatable("disconnect.spam", new Object[0]), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM)); // Paper - kick event cause + server.scheduleOnMain(() -> this.disconnect(Component.translatable("disconnect.spam", ArrayConstants.emptyObjectArray), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM)); // Paper - kick event cause // Gale - JettPack - reduce array allocations return; } // Paper start String str = packet.getCommand(); int index = -1; if (str.length() > 64 && ((index = str.indexOf(' ')) == -1 || index >= 64)) { - server.scheduleOnMain(() -> this.disconnect(Component.translatable("disconnect.spam", new Object[0]))); // Paper + server.scheduleOnMain(() -> this.disconnect(Component.translatable("disconnect.spam", ArrayConstants.emptyObjectArray), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM)); // Paper // Paper - kick event cause // Gale - JettPack - reduce array allocations return; } // Paper end @@ -3219,7 +3218,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl // Paper start if (!org.bukkit.Bukkit.isPrimaryThread()) { if (this.recipeSpamPackets.addAndGet(io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamIncrement) > io.papermc.paper.configuration.GlobalConfiguration.get().spamLimiter.recipeSpamLimit) { - this.server.scheduleOnMain(() -> this.disconnect(net.minecraft.network.chat.Component.translatable("disconnect.spam", new Object[0]), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM)); // Paper - kick event cause + this.server.scheduleOnMain(() -> this.disconnect(net.minecraft.network.chat.Component.translatable("disconnect.spam", ArrayConstants.emptyObjectArray), org.bukkit.event.player.PlayerKickEvent.Cause.SPAM)); // Paper - kick event cause // Gale - JettPack - reduce array allocations return; } } diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java index 8d67d9fd8f6d09f86c1f4829dcfb74324f32920e..bf17b7b29fb7ae3283a24d1174c55a31e51a96af 100644 --- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java @@ -13,9 +13,10 @@ import java.security.PrivateKey; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nullable; -import javax.crypto.Cipher; import javax.crypto.SecretKey; import net.minecraft.CrashReportCategory; + +import me.titaniumtown.ArrayConstants; import net.minecraft.DefaultUncaughtExceptionHandler; import net.minecraft.core.UUIDUtil; import net.minecraft.network.Connection; @@ -147,8 +148,10 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, @Override public void handleHello(ServerboundHelloPacket packet) { - Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", new Object[0]); - if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode() && io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.performUsernameValidation && !this.iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation) Validate.validState(Player.isValidUsername(packet.name()), "Invalid characters in username", new Object[0]); // Paper - config username validation + // Gale start - JettPack - reduce array allocations + Validate.validState(this.state == ServerLoginPacketListenerImpl.State.HELLO, "Unexpected hello packet", ArrayConstants.emptyObjectArray); + if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.isProxyOnlineMode() && io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.performUsernameValidation && !this.iKnowThisMayNotBeTheBestIdeaButPleaseDisableUsernameValidation) Validate.validState(Player.isValidUsername(packet.name()), "Invalid characters in username", ArrayConstants.emptyObjectArray); // Paper - config username validation + // Gale end - JettPack - reduce array allocations this.requestedUsername = packet.name(); GameProfile gameprofile = this.server.getSingleplayerProfile(); @@ -227,7 +230,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, @Override public void handleKey(ServerboundKeyPacket packet) { - Validate.validState(this.state == ServerLoginPacketListenerImpl.State.KEY, "Unexpected key packet", new Object[0]); + Validate.validState(this.state == ServerLoginPacketListenerImpl.State.KEY, "Unexpected key packet", ArrayConstants.emptyObjectArray); // Gale - JettPack - reduce array allocations final String s; @@ -409,7 +412,7 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, @Override public void handleLoginAcknowledgement(ServerboundLoginAcknowledgedPacket packet) { - Validate.validState(this.state == ServerLoginPacketListenerImpl.State.PROTOCOL_SWITCHING, "Unexpected login acknowledgement packet", new Object[0]); + Validate.validState(this.state == ServerLoginPacketListenerImpl.State.PROTOCOL_SWITCHING, "Unexpected login acknowledgement packet", ArrayConstants.emptyObjectArray); // Gale - JettPack - reduce array allocations CommonListenerCookie commonlistenercookie = CommonListenerCookie.createInitial((GameProfile) Objects.requireNonNull(this.authenticatedProfile)); ServerConfigurationPacketListenerImpl serverconfigurationpacketlistenerimpl = new ServerConfigurationPacketListenerImpl(this.server, this.connection, commonlistenercookie, this.player); // CraftBukkit diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java index 83eca7453559f182aa7e5fa735316be311e05e73..5eadc4ce30f77794f50b612549557f8b5d81f21a 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java @@ -25,6 +25,8 @@ import java.util.UUID; import java.util.function.Function; import java.util.function.Predicate; import javax.annotation.Nullable; + +import me.titaniumtown.ArrayConstants; import net.minecraft.ChatFormatting; import net.minecraft.FileUtil; import net.minecraft.commands.CommandSourceStack; @@ -723,7 +725,7 @@ public abstract class PlayerList { while (iterator.hasNext()) { entityplayer = (ServerPlayer) iterator.next(); this.save(entityplayer); // CraftBukkit - Force the player's inventory to be saved - entityplayer.connection.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login", new Object[0]), org.bukkit.event.player.PlayerKickEvent.Cause.DUPLICATE_LOGIN); // Paper - kick event cause + entityplayer.connection.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login", ArrayConstants.emptyObjectArray), org.bukkit.event.player.PlayerKickEvent.Cause.DUPLICATE_LOGIN); // Paper - kick event cause // Gale - JettPack - reduce array allocations } // Instead of kicking then returning, we need to store the kick reason diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java index 665120a62525f56912263a3e1b6f12f6c3e15dec..71e1c1a1ae59f74cfeea071aa6988f6fe47a286d 100644 --- a/src/main/java/net/minecraft/server/players/StoredUserList.java +++ b/src/main/java/net/minecraft/server/players/StoredUserList.java @@ -1,7 +1,6 @@ // mc-dev import package net.minecraft.server.players; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.io.Files; import com.google.gson.Gson; @@ -22,6 +21,8 @@ import java.util.Map; import java.util.Objects; import java.util.stream.Stream; import javax.annotation.Nullable; + +import me.titaniumtown.ArrayConstants; import net.minecraft.Util; import net.minecraft.util.GsonHelper; import org.slf4j.Logger; @@ -79,7 +80,7 @@ public abstract class StoredUserList> { } public String[] getUserList() { - return (String[]) this.map.keySet().toArray(new String[0]); + return (String[]) this.map.keySet().toArray(ArrayConstants.emptyStringArray); // Gale - JettPack - reduce array allocations } public boolean isEmpty() { diff --git a/src/main/java/net/minecraft/util/MemoryReserve.java b/src/main/java/net/minecraft/util/MemoryReserve.java index 0ee04fe6ff6a4d09754f326526ae04fe7226bab2..a4f7fee3ea112c8f7b0b94949f9eb899fc5be687 100644 --- a/src/main/java/net/minecraft/util/MemoryReserve.java +++ b/src/main/java/net/minecraft/util/MemoryReserve.java @@ -1,5 +1,7 @@ package net.minecraft.util; +import me.titaniumtown.ArrayConstants; + import javax.annotation.Nullable; public class MemoryReserve { @@ -11,6 +13,6 @@ public class MemoryReserve { } public static void release() { - reserve = new byte[0]; + reserve = ArrayConstants.emptyByteArray; // Gale - JettPack - reduce array allocations } } diff --git a/src/main/java/net/minecraft/util/ZeroBitStorage.java b/src/main/java/net/minecraft/util/ZeroBitStorage.java index 311625277a26c9c187025a1036978229241b965f..79b223ef3c86f3bc035e9abd84aa080b5d722f61 100644 --- a/src/main/java/net/minecraft/util/ZeroBitStorage.java +++ b/src/main/java/net/minecraft/util/ZeroBitStorage.java @@ -2,10 +2,11 @@ package net.minecraft.util; import java.util.Arrays; import java.util.function.IntConsumer; -import org.apache.commons.lang3.Validate; + +import me.titaniumtown.ArrayConstants; public class ZeroBitStorage implements BitStorage { - public static final long[] RAW = new long[0]; + public static final long[] RAW = ArrayConstants.emptyLongArray; // Gale - JettPack - reduce array allocations private final int size; public ZeroBitStorage(int size) { diff --git a/src/main/java/net/minecraft/world/entity/EquipmentSlot.java b/src/main/java/net/minecraft/world/entity/EquipmentSlot.java index 2e324276ea4cd9e528c6a3f9a9ba394b378fe075..8e91714e3167ab0ad16df681bc0807721a19ad71 100644 --- a/src/main/java/net/minecraft/world/entity/EquipmentSlot.java +++ b/src/main/java/net/minecraft/world/entity/EquipmentSlot.java @@ -15,6 +15,7 @@ public enum EquipmentSlot implements StringRepresentable { private final int index; private final int filterFlag; private final String name; + public static final EquipmentSlot[] VALUES = EquipmentSlot.values(); // Gale - JettPack - reduce array allocations private EquipmentSlot(EquipmentSlot.Type type, int entityId, int armorStandId, String name) { this.type = type; diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java index bd599625de84f33c7dbff8242dd2ee6d6c137d82..8597b9b5b78bb5375a10caea691cd19ac462d61f 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -3138,7 +3138,7 @@ public abstract class LivingEntity extends Entity implements Attackable { @Nullable private Map collectEquipmentChanges() { Map map = null; - EquipmentSlot[] aenumitemslot = EquipmentSlot.values(); + EquipmentSlot[] aenumitemslot = EquipmentSlot.VALUES; // Gale - JettPack - reduce array allocations int i = aenumitemslot.length; for (int j = 0; j < i; ++j) { diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java index 1cdacd42ea421833caef345a05fb53a8d93aec36..fe9fb934f9118f52e42109ff32e35f1dc95ffe09 100644 --- a/src/main/java/net/minecraft/world/entity/Mob.java +++ b/src/main/java/net/minecraft/world/entity/Mob.java @@ -1056,7 +1056,7 @@ public abstract class Mob extends LivingEntity implements Targeting { @Override protected void dropCustomDeathLoot(DamageSource source, int lootingMultiplier, boolean allowDrops) { super.dropCustomDeathLoot(source, lootingMultiplier, allowDrops); - EquipmentSlot[] aenumitemslot = EquipmentSlot.values(); + EquipmentSlot[] aenumitemslot = EquipmentSlot.VALUES; // Gale - JettPack - reduce array allocations int j = aenumitemslot.length; for (int k = 0; k < j; ++k) { @@ -1118,7 +1118,7 @@ public abstract class Mob extends LivingEntity implements Targeting { } boolean flag = true; - EquipmentSlot[] aenumitemslot = EquipmentSlot.values(); + EquipmentSlot[] aenumitemslot = EquipmentSlot.VALUES; // Gale - JettPack - reduce array allocations int j = aenumitemslot.length; for (int k = 0; k < j; ++k) { @@ -1205,7 +1205,7 @@ public abstract class Mob extends LivingEntity implements Targeting { float f = localDifficulty.getSpecialMultiplier(); this.enchantSpawnedWeapon(random, f); - EquipmentSlot[] aenumitemslot = EquipmentSlot.values(); + EquipmentSlot[] aenumitemslot = EquipmentSlot.VALUES; // Gale - JettPack - reduce array allocations int i = aenumitemslot.length; for (int j = 0; j < i; ++j) { @@ -1424,7 +1424,7 @@ public abstract class Mob extends LivingEntity implements Targeting { t0.setInvulnerable(this.isInvulnerable()); if (flag) { t0.setCanPickUpLoot(this.canPickUpLoot()); - EquipmentSlot[] aenumitemslot = EquipmentSlot.values(); + EquipmentSlot[] aenumitemslot = EquipmentSlot.VALUES; // Gale - JettPack - reduce array allocations int i = aenumitemslot.length; for (int j = 0; j < i; ++j) { diff --git a/src/main/java/net/minecraft/world/entity/monster/ZombieVillager.java b/src/main/java/net/minecraft/world/entity/monster/ZombieVillager.java index 94396ad1a3c280787d36c6c18256d10340ace488..9e139c1291f40fd730754ac2427269b102f7cede 100644 --- a/src/main/java/net/minecraft/world/entity/monster/ZombieVillager.java +++ b/src/main/java/net/minecraft/world/entity/monster/ZombieVillager.java @@ -237,7 +237,7 @@ public class ZombieVillager extends Zombie implements VillagerDataHolder { return; } // CraftBukkit end - EquipmentSlot[] aenumitemslot = EquipmentSlot.values(); + EquipmentSlot[] aenumitemslot = EquipmentSlot.VALUES; // Gale - JettPack - reduce array allocations int i = aenumitemslot.length; for (int j = 0; j < i; ++j) { diff --git a/src/main/java/net/minecraft/world/item/ItemStack.java b/src/main/java/net/minecraft/world/item/ItemStack.java index 5b8a1f31e0b55da15daa4ab271317e4393a87e96..ca037db7ea68ad01b4189154a38a01bf3351c7b3 100644 --- a/src/main/java/net/minecraft/world/item/ItemStack.java +++ b/src/main/java/net/minecraft/world/item/ItemStack.java @@ -1052,7 +1052,7 @@ public final class ItemStack { int k; if (ItemStack.shouldShowInTooltip(i, ItemStack.TooltipPart.MODIFIERS)) { - EquipmentSlot[] aenumitemslot = EquipmentSlot.values(); + EquipmentSlot[] aenumitemslot = EquipmentSlot.VALUES; // Gale - JettPack - reduce array allocations k = aenumitemslot.length; diff --git a/src/main/java/net/minecraft/world/item/crafting/ShapedRecipePattern.java b/src/main/java/net/minecraft/world/item/crafting/ShapedRecipePattern.java index 27dc0e4ce21ccf641ea16fd6d2dc1c28fcf62df8..81c9ba1d3455d1eb6619cb04d4e52a7226b2518f 100644 --- a/src/main/java/net/minecraft/world/item/crafting/ShapedRecipePattern.java +++ b/src/main/java/net/minecraft/world/item/crafting/ShapedRecipePattern.java @@ -11,6 +11,8 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.function.Function; + +import me.titaniumtown.ArrayConstants; import net.minecraft.Util; import net.minecraft.core.NonNullList; import net.minecraft.network.FriendlyByteBuf; @@ -89,7 +91,7 @@ public record ShapedRecipePattern(int width, int height, NonNullList } if (pattern.size() == l) { - return new String[0]; + return ArrayConstants.emptyStringArray; // Gale - JettPack - reduce array allocations } else { String[] strings = new String[pattern.size() - l - k]; diff --git a/src/main/java/net/minecraft/world/item/enchantment/Enchantments.java b/src/main/java/net/minecraft/world/item/enchantment/Enchantments.java index 6c2e8049c2197ddc912c1a0fc99c87beae81e25b..a13822a22ab524a0fb9fd998c4ada06b6e10e182 100644 --- a/src/main/java/net/minecraft/world/item/enchantment/Enchantments.java +++ b/src/main/java/net/minecraft/world/item/enchantment/Enchantments.java @@ -43,8 +43,10 @@ public class Enchantments { public static final Enchantment MULTISHOT = register("multishot", new MultiShotEnchantment(Enchantment.Rarity.RARE, EquipmentSlot.MAINHAND)); public static final Enchantment QUICK_CHARGE = register("quick_charge", new QuickChargeEnchantment(Enchantment.Rarity.UNCOMMON, EquipmentSlot.MAINHAND)); public static final Enchantment PIERCING = register("piercing", new ArrowPiercingEnchantment(Enchantment.Rarity.COMMON, EquipmentSlot.MAINHAND)); - public static final Enchantment MENDING = register("mending", new MendingEnchantment(Enchantment.Rarity.RARE, EquipmentSlot.values())); - public static final Enchantment VANISHING_CURSE = register("vanishing_curse", new VanishingCurseEnchantment(Enchantment.Rarity.VERY_RARE, EquipmentSlot.values())); + // Gale start - JettPack - reduce array allocations + public static final Enchantment MENDING = register("mending", new MendingEnchantment(Enchantment.Rarity.RARE, EquipmentSlot.VALUES)); + public static final Enchantment VANISHING_CURSE = register("vanishing_curse", new VanishingCurseEnchantment(Enchantment.Rarity.VERY_RARE, EquipmentSlot.VALUES)); + // Gale end - JettPack - reduce array allocations private static Enchantment register(String name, Enchantment enchantment) { return Registry.register(BuiltInRegistries.ENCHANTMENT, name, enchantment); diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java index 6d5a7d4609ec9068c60ac29a8fad2807d0abd48c..8b7dbd6bbd848c0cfb30fd91c600432d9dfc0fbf 100644 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -12,6 +12,8 @@ import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; import javax.annotation.Nullable; + +import me.titaniumtown.ArrayConstants; import net.minecraft.CrashReport; import net.minecraft.CrashReportCategory; import net.minecraft.core.BlockPos; @@ -1851,7 +1853,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable { public org.bukkit.entity.Entity[] getChunkEntities(int chunkX, int chunkZ) { io.papermc.paper.world.ChunkEntitySlices slices = ((ServerLevel)this).getEntityLookup().getChunk(chunkX, chunkZ); if (slices == null) { - return new org.bukkit.entity.Entity[0]; + return ArrayConstants.emptyBukkitEntityArray; // Gale - JettPack - reduce array allocations } return slices.getChunkEntities(); } diff --git a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java index de8b5cab7925c1c46478952ed2cb2bd40f9a9c48..ce43cb260b36ca170a1d1725a7bf02525e8970d6 100644 --- a/src/main/java/net/minecraft/world/level/block/ComposterBlock.java +++ b/src/main/java/net/minecraft/world/level/block/ComposterBlock.java @@ -4,6 +4,8 @@ import com.mojang.serialization.MapCodec; import it.unimi.dsi.fastutil.objects.Object2FloatMap; import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap; import javax.annotation.Nullable; + +import me.titaniumtown.ArrayConstants; import net.minecraft.Util; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -422,7 +424,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 ? ArrayConstants.zeroSingletonIntArray : ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations } @Override @@ -471,7 +473,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 ? ArrayConstants.zeroSingletonIntArray : ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations } @Override @@ -513,7 +515,7 @@ public class ComposterBlock extends Block implements WorldlyContainerHolder { @Override public int[] getSlotsForFace(Direction side) { - return new int[0]; + return ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations } @Override diff --git a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java index a18aadbf7ae83713e1f2b21553185d8000bc7699..13e100fd2400878c819c7115bb958586face9958 100644 --- a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java @@ -9,6 +9,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import javax.annotation.Nullable; + +import me.titaniumtown.ArrayConstants; import net.minecraft.SharedConstants; import net.minecraft.Util; import net.minecraft.core.BlockPos; @@ -65,7 +67,7 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit 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; // Gale - JettPack - 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; diff --git a/src/main/java/net/minecraft/world/level/storage/PlayerDataStorage.java b/src/main/java/net/minecraft/world/level/storage/PlayerDataStorage.java index b3a90d6ef0e17c236e0b3c46e2d0012671afdaa7..9c82568d31da70e30c45dbb41be48026eb0dc85a 100644 --- a/src/main/java/net/minecraft/world/level/storage/PlayerDataStorage.java +++ b/src/main/java/net/minecraft/world/level/storage/PlayerDataStorage.java @@ -6,13 +6,14 @@ import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import javax.annotation.Nullable; + +import me.titaniumtown.ArrayConstants; import net.minecraft.Util; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtAccounter; import net.minecraft.nbt.NbtIo; import net.minecraft.nbt.NbtUtils; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.datafix.DataFixTypes; import net.minecraft.world.entity.player.Player; import org.slf4j.Logger; @@ -124,7 +125,7 @@ public class PlayerDataStorage { String[] astring = this.playerDir.list(); if (astring == null) { - astring = new String[0]; + astring = ArrayConstants.emptyStringArray; // Gale - JettPack - reduce array allocations } for (int i = 0; i < astring.length; ++i) { diff --git a/src/main/java/net/minecraft/world/scores/Team.java b/src/main/java/net/minecraft/world/scores/Team.java index 16d2aa4556bc9f32a2def7f9ca282aa3fa23fb87..ad9a78f56aeb93895d1caefd6f59326dbf33d18f 100644 --- a/src/main/java/net/minecraft/world/scores/Team.java +++ b/src/main/java/net/minecraft/world/scores/Team.java @@ -5,6 +5,8 @@ import java.util.Collection; import java.util.Map; import java.util.stream.Collectors; import javax.annotation.Nullable; + +import me.titaniumtown.ArrayConstants; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; @@ -80,7 +82,7 @@ public abstract class Team { public final int id; public static String[] getAllNames() { - return BY_NAME.keySet().toArray(new String[0]); + return BY_NAME.keySet().toArray(ArrayConstants.emptyStringArray); // Gale - JettPack - reduce array allocations } @Nullable diff --git a/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java b/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java index 402a238cf502003a232bb95473bd13e59e067fab..ea8d69acfe4452eaa48ea30559ba606c28e3abfc 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java @@ -5,8 +5,10 @@ import org.bukkit.inventory.EquipmentSlot; public class CraftEquipmentSlot { - private static final net.minecraft.world.entity.EquipmentSlot[] slots = new net.minecraft.world.entity.EquipmentSlot[EquipmentSlot.values().length]; - private static final EquipmentSlot[] enums = new EquipmentSlot[net.minecraft.world.entity.EquipmentSlot.values().length]; + // Gale start - JettPack - reduce array allocations + private static final net.minecraft.world.entity.EquipmentSlot[] slots = net.minecraft.world.entity.EquipmentSlot.VALUES; + private static final EquipmentSlot[] enums = new EquipmentSlot[net.minecraft.world.entity.EquipmentSlot.VALUES.length]; + // Gale end - JettPack - reduce array allocations static { set(EquipmentSlot.HAND, net.minecraft.world.entity.EquipmentSlot.MAINHAND); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java index 6827979a5b270ced53b46ecb9eff548727dadb81..8cecb6eddee0c3cafaecc3cc4d7cf99f3ce1ccea 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java @@ -165,7 +165,7 @@ public class CraftEntityEquipment implements EntityEquipment { @Override public void clear() { - for (net.minecraft.world.entity.EquipmentSlot slot : net.minecraft.world.entity.EquipmentSlot.values()) { + for (net.minecraft.world.entity.EquipmentSlot slot : net.minecraft.world.entity.EquipmentSlot.VALUES) { // Gale - JettPack - reduce array allocations this.setEquipment(slot, null, false); } } diff --git a/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java b/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java index b25dc23b81687dd4d4e70b3615ffb91f8c03c68b..b662ebb89f8b00238e6c96de3c134413ea28def8 100644 --- a/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java +++ b/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java @@ -7,6 +7,8 @@ import java.util.Collection; import java.util.Iterator; import java.util.NoSuchElementException; +import me.titaniumtown.ArrayConstants; + public final class WeakCollection implements Collection { static final Object NO_VALUE = new Object(); private final Collection> collection; @@ -164,7 +166,7 @@ public final class WeakCollection implements Collection { @Override public Object[] toArray() { - return this.toArray(new Object[0]); + return this.toArray(ArrayConstants.emptyObjectArray); // Gale - JettPack - reduce array allocations } @Override diff --git a/src/main/java/org/galemc/gale/command/GaleCommand.java b/src/main/java/org/galemc/gale/command/GaleCommand.java index 87d3aed35341dfa9358af064dd54d7de95078269..034dd291cdd7d1f71c2714e361112533e091420e 100644 --- a/src/main/java/org/galemc/gale/command/GaleCommand.java +++ b/src/main/java/org/galemc/gale/command/GaleCommand.java @@ -4,6 +4,7 @@ package org.galemc.gale.command; import io.papermc.paper.command.CommandUtil; import it.unimi.dsi.fastutil.Pair; +import me.titaniumtown.ArrayConstants; import net.minecraft.Util; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -140,7 +141,7 @@ public final class GaleCommand extends Command { // If they did not give a subcommand if (args.length == 0) { - INFO_SUBCOMMAND.execute(sender, InfoCommand.LITERAL_ARGUMENT, new String[0]); + INFO_SUBCOMMAND.execute(sender, InfoCommand.LITERAL_ARGUMENT, ArrayConstants.emptyStringArray); // Gale - JettPack - reduce array allocations sender.sendMessage(newline().append(text("Command usage: " + specificUsageMessage, GRAY))); return false; } diff --git a/src/main/java/org/galemc/gale/command/subcommands/VersionCommand.java b/src/main/java/org/galemc/gale/command/subcommands/VersionCommand.java index 675cd4295dabfade1b9cc5473010b5b20dc32039..509751f640a195e4aacd2b651f9af39627f84bfd 100644 --- a/src/main/java/org/galemc/gale/command/subcommands/VersionCommand.java +++ b/src/main/java/org/galemc/gale/command/subcommands/VersionCommand.java @@ -2,6 +2,7 @@ package org.galemc.gale.command.subcommands; +import me.titaniumtown.ArrayConstants; import net.minecraft.server.MinecraftServer; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -26,7 +27,7 @@ public final class VersionCommand extends PermissionedGaleSubcommand { public boolean execute(final CommandSender sender, final String subCommand, final String[] args) { final @Nullable Command ver = MinecraftServer.getServer().server.getCommandMap().getCommand("version"); if (ver != null) { - ver.execute(sender, GaleCommand.COMMAND_LABEL, new String[0]); + ver.execute(sender, GaleCommand.COMMAND_LABEL, ArrayConstants.emptyStringArray); // Gale - JettPack - reduce array allocations } return true; }