mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
152 lines
8.1 KiB
Diff
152 lines
8.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
|
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 <titaniumtown@gmail.com>
|
|
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/ca/spottedleaf/moonrise/common/list/EntityList.java b/src/main/java/ca/spottedleaf/moonrise/common/list/EntityList.java
|
|
index 7fed43a1e7bcf35c4d7fd3224837a47fedd59860..adc47f1ca3580a6968d145239ae830734a0ebe4a 100644
|
|
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/EntityList.java
|
|
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/EntityList.java
|
|
@@ -18,9 +18,7 @@ public final class EntityList implements Iterable<Entity> {
|
|
this.entityToIndex.defaultReturnValue(Integer.MIN_VALUE);
|
|
}
|
|
|
|
- private static final Entity[] EMPTY_LIST = new Entity[0];
|
|
-
|
|
- private Entity[] entities = EMPTY_LIST;
|
|
+ private Entity[] entities = me.titaniumtown.ArrayConstants.emptyEntityArray; // Gale - JettPack - reduce array allocations
|
|
private int count;
|
|
|
|
public int size() {
|
|
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/list/IntList.java b/src/main/java/ca/spottedleaf/moonrise/common/list/IntList.java
|
|
index 9f3b25bb2439f283f878db93973a02fcdcd14eed..4eb7bf187276f07f807fe181b303dda8e1b9196d 100644
|
|
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/IntList.java
|
|
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/IntList.java
|
|
@@ -10,9 +10,7 @@ public final class IntList {
|
|
this.map.defaultReturnValue(Integer.MIN_VALUE);
|
|
}
|
|
|
|
- private static final int[] EMPTY_LIST = new int[0];
|
|
-
|
|
- private int[] byIndex = EMPTY_LIST;
|
|
+ private int[] byIndex = me.titaniumtown.ArrayConstants.emptyIntArray; // Gale - JettPack - reduce array allocations
|
|
private int count;
|
|
|
|
public int size() {
|
|
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/list/ReferenceList.java b/src/main/java/ca/spottedleaf/moonrise/common/list/ReferenceList.java
|
|
index 2e876b918672e8ef3b5197b7e6b1597247fdeaa1..8df9406b77eb3c225ebf88bf76a7adb666452f3b 100644
|
|
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/ReferenceList.java
|
|
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/ReferenceList.java
|
|
@@ -7,14 +7,12 @@ import java.util.NoSuchElementException;
|
|
|
|
public final class ReferenceList<E> implements Iterable<E> {
|
|
|
|
- private static final Object[] EMPTY_LIST = new Object[0];
|
|
-
|
|
private final Reference2IntOpenHashMap<E> referenceToIndex;
|
|
private E[] references;
|
|
private int count;
|
|
|
|
public ReferenceList() {
|
|
- this((E[])EMPTY_LIST);
|
|
+ this((E[]) me.titaniumtown.ArrayConstants.emptyObjectArray); // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
public ReferenceList(final E[] referenceArray) {
|
|
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/list/ShortList.java b/src/main/java/ca/spottedleaf/moonrise/common/list/ShortList.java
|
|
index 2bae9949ef325d0001aa638150fbbdf968367e75..a72d5db6f6a8667c5c839016033bba4d0f16cf13 100644
|
|
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/ShortList.java
|
|
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/ShortList.java
|
|
@@ -10,9 +10,7 @@ public final class ShortList {
|
|
this.map.defaultReturnValue(Short.MIN_VALUE);
|
|
}
|
|
|
|
- private static final short[] EMPTY_LIST = new short[0];
|
|
-
|
|
- private short[] byIndex = EMPTY_LIST;
|
|
+ private short[] byIndex = me.titaniumtown.ArrayConstants.emptyShortArray; // Gale - JettPack - reduce array allocations
|
|
private short count;
|
|
|
|
public int size() {
|
|
diff --git a/src/main/java/ca/spottedleaf/moonrise/common/list/SortedList.java b/src/main/java/ca/spottedleaf/moonrise/common/list/SortedList.java
|
|
index db92261a6cb3758391108361096417c61bc82cdc..1a14fddb36ca3c14d243304db629d0c5aac3906c 100644
|
|
--- a/src/main/java/ca/spottedleaf/moonrise/common/list/SortedList.java
|
|
+++ b/src/main/java/ca/spottedleaf/moonrise/common/list/SortedList.java
|
|
@@ -6,14 +6,12 @@ import java.util.Comparator;
|
|
|
|
public final class SortedList<E> {
|
|
|
|
- private static final Object[] EMPTY_LIST = new Object[0];
|
|
-
|
|
private Comparator<? super E> comparator;
|
|
private E[] elements;
|
|
private int count;
|
|
|
|
public SortedList(final Comparator<? super E> comparator) {
|
|
- this((E[])EMPTY_LIST, comparator);
|
|
+ this((E[]) me.titaniumtown.ArrayConstants.emptyObjectArray, comparator); // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
public SortedList(final E[] elements, final Comparator<? super E> comparator) {
|
|
diff --git a/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java b/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java
|
|
index af480008adc07c63344d625101d1bf42fab96b5d..8c9609b95cf27b6316c48a554b2c508aa527b964 100644
|
|
--- a/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java
|
|
+++ b/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java
|
|
@@ -178,7 +178,7 @@ public class PaperCommands implements Commands, PaperRegistrar<LifecycleEventOwn
|
|
})
|
|
)
|
|
.executes((stack) -> {
|
|
- basicCommand.execute(stack.getSource(), new String[0]);
|
|
+ basicCommand.execute(stack.getSource(), me.titaniumtown.ArrayConstants.emptyStringArray); // Gale - JettPack - reduce array allocations
|
|
return com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
|
});
|
|
|
|
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 58ca24715eafd1ac3cc9657b1cc235049d69bb59..acb764b71bb3e8f159a758002f7d1077637d188d 100644
|
|
--- a/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java
|
|
+++ b/src/main/java/io/papermc/paper/command/subcommands/VersionCommand.java
|
|
@@ -14,7 +14,7 @@ public final class VersionCommand implements PaperSubcommand {
|
|
public boolean execute(final CommandSender sender, final String subCommand, final String[] args) {
|
|
final @Nullable Command redirect = MinecraftServer.getServer().server.getCommandMap().getCommand("version");
|
|
if (redirect != null) {
|
|
- redirect.execute(sender, "paper", new String[0]);
|
|
+ redirect.execute(sender, "paper", me.titaniumtown.ArrayConstants.emptyStringArray); // Gale - JettPack - reduce array allocations
|
|
}
|
|
return true;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftEntityEquipment.java
|
|
index 4abe58077fae4e68cceda9624fed013bca1d6f22..72aa906ccf64dd9be085728a897f323ab0822eba 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 306ca8db11d16a03ce73b9a5a8be7efc11ee4b57..444e57a87acb653275d1cadbd0698815f6dc049d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/WeakCollection.java
|
|
@@ -164,7 +164,7 @@ public final class WeakCollection<E> implements Collection<E> {
|
|
|
|
@Override
|
|
public Object[] toArray() {
|
|
- return this.toArray(new Object[0]);
|
|
+ return this.toArray(me.titaniumtown.ArrayConstants.emptyObjectArray); // Gale - JettPack - reduce array allocations
|
|
}
|
|
|
|
@Override
|