From dd84615ca117586664b8dbda55b5a24fea4efd0d Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 4 Apr 2024 15:26:32 -0400 Subject: [PATCH] Optimization moved to method --- src/engine/Enum.java | 5 +++++ src/engine/objects/ItemTemplate.java | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 08e9685e..38612cd0 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -40,6 +40,11 @@ public class Enum { EnumSet enumSet = EnumSet.noneOf(enumClass); + // Early exit if empty set + + if (bitVector == 0) + return enumSet; + for (E enumValue : enumClass.getEnumConstants()) { if ((bitVector & (1L << enumValue.ordinal())) != 0) { enumSet.add(enumValue); diff --git a/src/engine/objects/ItemTemplate.java b/src/engine/objects/ItemTemplate.java index 580e0b52..81d7ca2c 100644 --- a/src/engine/objects/ItemTemplate.java +++ b/src/engine/objects/ItemTemplate.java @@ -497,13 +497,11 @@ public class ItemTemplate { int group_tactics_bitvector = ((Long) jsonObject.get("rune_group_tactics")).intValue(); - if (group_tactics_bitvector != 0) - rune_group_tactics.addAll(Enum.fromLong(group_tactics_bitvector, Enum.MobBehaviourType.class)); + rune_group_tactics.addAll(Enum.fromLong(group_tactics_bitvector, Enum.MobBehaviourType.class)); int group_role_bitvector = ((Long) jsonObject.get("rune_group_role_set")).intValue(); - if (group_role_bitvector != 0) - rune_group_role_set.addAll(Enum.fromLong(group_role_bitvector, Enum.MobBehaviourType.class)); + rune_group_role_set.addAll(Enum.fromLong(group_role_bitvector, Enum.MobBehaviourType.class)); JSONArray enemy_types_json = (JSONArray) jsonObject.get("rune_enemy_monster_types");