From c3284030a3764cd418e450948365f495a93bbfc4 Mon Sep 17 00:00:00 2001 From: layue13 Date: Sat, 5 Sep 2026 16:12:44 +0800 Subject: [PATCH] =?UTF-8?q?perf(slashblade-allweapon):=20=E5=8A=A0?= =?UTF-8?q?=E9=80=9F=E5=BC=B9=E4=BD=93=E5=91=BD=E4=B8=AD=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原因 / Cause: 四类弹体每次实体扫描后都以 ArrayList.removeAll 进行已命中排除,候选与历史命中数增长时成员检查退化为线性。 修复 / Fix: 将仅作成员记录的 alreadyHitEntity 从 ArrayList 替换为 HashSet,保留原有 add、clear、addAll 与 removeAll 调用顺序。 性能收益 / Performance: 实体扫描结果排除已命中目标时,成员检查由线性查找降为均摊常数时间,降低多弹体和多目标场景的去重开销。 兼容性 / Compatibility: 不改变 AABB、selector、攻击顺序、命中冷却或弹体生命周期;集合未被迭代,命中列表的顺序和重复值不参与行为。 验证 / Validation: Java 25 下执行 Gradle 9.4.0 build --no-daemon --console=plain 成功(test 为 NO-SOURCE)。 Refs #1 --- .../java/com/moe/allweapon/Entityadd/EntityDriveAdd.java | 5 +++-- .../com/moe/allweapon/Entityadd/EntitySlashDimensionAdd.java | 5 +++-- .../com/moe/allweapon/Entityadd/EntitySummonedButterfly.java | 5 +++-- .../com/moe/allweapon/Entityadd/EntitySummonedSwordAdd.java | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/moe/allweapon/Entityadd/EntityDriveAdd.java b/src/main/java/com/moe/allweapon/Entityadd/EntityDriveAdd.java index 8ddb9df..e29c5be 100644 --- a/src/main/java/com/moe/allweapon/Entityadd/EntityDriveAdd.java +++ b/src/main/java/com/moe/allweapon/Entityadd/EntityDriveAdd.java @@ -30,10 +30,11 @@ package com.moe.allweapon.Entityadd; import cpw.mods.fml.common.registry.IThrowableEntity; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Random; +import java.util.Set; import mods.flammpfeil.slashblade.ItemSlashBlade; import mods.flammpfeil.slashblade.ability.StylishRankManager; import net.minecraft.block.Block; @@ -58,7 +59,7 @@ extends Entity implements IThrowableEntity { protected Entity thrower; protected ItemStack blade = null; - protected List alreadyHitEntity = new ArrayList(); + protected Set alreadyHitEntity = new HashSet(); protected float AttackLevel = 0.0f; private int i; private Long startTime = new Date().getTime(); diff --git a/src/main/java/com/moe/allweapon/Entityadd/EntitySlashDimensionAdd.java b/src/main/java/com/moe/allweapon/Entityadd/EntitySlashDimensionAdd.java index 06c5f11..b5bdd37 100644 --- a/src/main/java/com/moe/allweapon/Entityadd/EntitySlashDimensionAdd.java +++ b/src/main/java/com/moe/allweapon/Entityadd/EntitySlashDimensionAdd.java @@ -30,9 +30,10 @@ package com.moe.allweapon.Entityadd; import cpw.mods.fml.common.registry.IThrowableEntity; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Random; +import java.util.Set; import mods.flammpfeil.slashblade.ItemSlashBlade; import mods.flammpfeil.slashblade.ability.StylishRankManager; import mods.flammpfeil.slashblade.ability.TeleportCanceller; @@ -57,7 +58,7 @@ extends Entity implements IThrowableEntity { protected Entity thrower; protected ItemStack blade = null; - protected List alreadyHitEntity = new ArrayList(); + protected Set alreadyHitEntity = new HashSet(); protected float AttackLevel = 0.0f; private static final int LIFETIME = 3; private static final int SINGLE_HIT = 4; diff --git a/src/main/java/com/moe/allweapon/Entityadd/EntitySummonedButterfly.java b/src/main/java/com/moe/allweapon/Entityadd/EntitySummonedButterfly.java index 02e7483..f7c2e84 100644 --- a/src/main/java/com/moe/allweapon/Entityadd/EntitySummonedButterfly.java +++ b/src/main/java/com/moe/allweapon/Entityadd/EntitySummonedButterfly.java @@ -34,11 +34,12 @@ import com.moe.allweapon.Entityadd.EntitySummonedSwordAdd; import cpw.mods.fml.common.registry.IThrowableEntity; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.WeakHashMap; import mods.flammpfeil.slashblade.ItemSlashBlade; import mods.flammpfeil.slashblade.ability.StylishRankManager; @@ -70,7 +71,7 @@ IThrowableEntity { private static final Map playerHitCooldown = Collections.synchronizedMap(new WeakHashMap()); protected Entity thrower; protected ItemStack blade = null; - protected List alreadyHitEntity = new ArrayList(); + protected Set alreadyHitEntity = new HashSet(); protected float AttackLevel = 0.0f; static final int THROWER_ENTITY_ID = 11; float speed = 0.0f; diff --git a/src/main/java/com/moe/allweapon/Entityadd/EntitySummonedSwordAdd.java b/src/main/java/com/moe/allweapon/Entityadd/EntitySummonedSwordAdd.java index 688de07..3208f7a 100644 --- a/src/main/java/com/moe/allweapon/Entityadd/EntitySummonedSwordAdd.java +++ b/src/main/java/com/moe/allweapon/Entityadd/EntitySummonedSwordAdd.java @@ -33,11 +33,12 @@ package com.moe.allweapon.Entityadd; import cpw.mods.fml.common.registry.IThrowableEntity; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Set; import java.util.WeakHashMap; import mods.flammpfeil.slashblade.ItemSlashBlade; import mods.flammpfeil.slashblade.ability.StylishRankManager; @@ -69,7 +70,7 @@ IThrowableEntity { private static final Map playerHitCooldown = Collections.synchronizedMap(new WeakHashMap()); protected Entity thrower; protected ItemStack blade = null; - protected List alreadyHitEntity = new ArrayList(); + protected Set alreadyHitEntity = new HashSet(); protected float AttackLevel = 0.0f; static final int THROWER_ENTITY_ID = 11; float speed = 0.0f;