diff --git a/Dalamud/Game/ClientState/Aetherytes/AetheryteList.cs b/Dalamud/Game/ClientState/Aetherytes/AetheryteList.cs index a24302947..12a629958 100644 --- a/Dalamud/Game/ClientState/Aetherytes/AetheryteList.cs +++ b/Dalamud/Game/ClientState/Aetherytes/AetheryteList.cs @@ -99,7 +99,7 @@ internal sealed partial class AetheryteList private struct Enumerator(AetheryteList aetheryteList) : IEnumerator { - private int index = 0; + private int index = -1; public IAetheryteEntry Current { get; private set; } @@ -107,15 +107,19 @@ internal sealed partial class AetheryteList public bool MoveNext() { - if (this.index == aetheryteList.Length) return false; - this.Current = aetheryteList[this.index]; - this.index++; - return true; + if (++this.index < aetheryteList.Length) + { + this.Current = aetheryteList[this.index]; + return true; + } + + this.Current = default; + return false; } public void Reset() { - this.index = 0; + this.index = -1; } public void Dispose() diff --git a/Dalamud/Game/ClientState/Buddy/BuddyList.cs b/Dalamud/Game/ClientState/Buddy/BuddyList.cs index b8e4c0fcc..3bec6d9f1 100644 --- a/Dalamud/Game/ClientState/Buddy/BuddyList.cs +++ b/Dalamud/Game/ClientState/Buddy/BuddyList.cs @@ -141,7 +141,7 @@ internal sealed partial class BuddyList private struct Enumerator(BuddyList buddyList) : IEnumerator { - private int index = 0; + private int index = -1; public IBuddyMember Current { get; private set; } @@ -149,15 +149,19 @@ internal sealed partial class BuddyList public bool MoveNext() { - if (this.index == buddyList.Length) return false; - this.Current = buddyList[this.index]; - this.index++; - return true; + if (++this.index < buddyList.Length) + { + this.Current = buddyList[this.index]; + return true; + } + + this.Current = default; + return false; } public void Reset() { - this.index = 0; + this.index = -1; } public void Dispose() diff --git a/Dalamud/Game/ClientState/Fates/FateTable.cs b/Dalamud/Game/ClientState/Fates/FateTable.cs index fa75c7e53..41e974f04 100644 --- a/Dalamud/Game/ClientState/Fates/FateTable.cs +++ b/Dalamud/Game/ClientState/Fates/FateTable.cs @@ -115,7 +115,7 @@ internal sealed partial class FateTable private struct Enumerator(FateTable fateTable) : IEnumerator { - private int index = 0; + private int index = -1; public IFate Current { get; private set; } @@ -123,15 +123,19 @@ internal sealed partial class FateTable public bool MoveNext() { - if (this.index == fateTable.Length) return false; - this.Current = fateTable[this.index]; - this.index++; - return true; + if (++this.index < fateTable.Length) + { + this.Current = fateTable[this.index]; + return true; + } + + this.Current = default; + return false; } public void Reset() { - this.index = 0; + this.index = -1; } public void Dispose() diff --git a/Dalamud/Game/ClientState/Objects/ObjectTable.cs b/Dalamud/Game/ClientState/Objects/ObjectTable.cs index 6bbc43235..9a2c7343e 100644 --- a/Dalamud/Game/ClientState/Objects/ObjectTable.cs +++ b/Dalamud/Game/ClientState/Objects/ObjectTable.cs @@ -246,17 +246,15 @@ internal sealed partial class ObjectTable { private int index = -1; - public IGameObject Current { get; private set; } = null!; + public IGameObject Current { get; private set; } object IEnumerator.Current => this.Current; public bool MoveNext() { - if (this.index == objectTableLength) - return false; - var cache = owner.cachedObjectTable.AsSpan(); - for (this.index++; this.index < objectTableLength; this.index++) + + while (++this.index < objectTableLength) { if (cache[this.index].Update() is { } ao) { @@ -265,10 +263,14 @@ internal sealed partial class ObjectTable } } + this.Current = default; return false; } - public void Reset() => this.index = -1; + public void Reset() + { + this.index = -1; + } public void Dispose() { diff --git a/Dalamud/Game/ClientState/Party/PartyList.cs b/Dalamud/Game/ClientState/Party/PartyList.cs index 1dede1dd3..90959f926 100644 --- a/Dalamud/Game/ClientState/Party/PartyList.cs +++ b/Dalamud/Game/ClientState/Party/PartyList.cs @@ -143,7 +143,7 @@ internal sealed partial class PartyList private struct Enumerator(PartyList partyList) : IEnumerator { - private int index = 0; + private int index = -1; public IPartyMember Current { get; private set; } @@ -151,9 +151,7 @@ internal sealed partial class PartyList public bool MoveNext() { - if (this.index == partyList.Length) return false; - - for (; this.index < partyList.Length; this.index++) + while (++this.index < partyList.Length) { var partyMember = partyList[this.index]; if (partyMember != null) @@ -163,12 +161,13 @@ internal sealed partial class PartyList } } + this.Current = default; return false; } public void Reset() { - this.index = 0; + this.index = -1; } public void Dispose() diff --git a/Dalamud/Game/ClientState/Statuses/StatusList.cs b/Dalamud/Game/ClientState/Statuses/StatusList.cs index 81469ba93..43650a48c 100644 --- a/Dalamud/Game/ClientState/Statuses/StatusList.cs +++ b/Dalamud/Game/ClientState/Statuses/StatusList.cs @@ -153,7 +153,7 @@ public sealed partial class StatusList : IReadOnlyCollection, ICollecti private struct Enumerator(StatusList statusList) : IEnumerator { - private int index = 0; + private int index = -1; public IStatus Current { get; private set; } @@ -161,9 +161,7 @@ public sealed partial class StatusList : IReadOnlyCollection, ICollecti public bool MoveNext() { - if (this.index == statusList.Length) return false; - - for (; this.index < statusList.Length; this.index++) + while (++this.index < statusList.Length) { var status = statusList[this.index]; if (status != null && status.StatusId != 0) @@ -173,12 +171,13 @@ public sealed partial class StatusList : IReadOnlyCollection, ICollecti } } + this.Current = default; return false; } public void Reset() { - this.index = 0; + this.index = -1; } public void Dispose()