Better enumerator code

This commit is contained in:
Haselnussbomber 2025-12-16 09:48:59 +01:00
parent 2e7c48316f
commit 1c1b60efee
No known key found for this signature in database
GPG key ID: BB905BB49E7295D1
6 changed files with 46 additions and 34 deletions

View file

@ -99,7 +99,7 @@ internal sealed partial class AetheryteList
private struct Enumerator(AetheryteList aetheryteList) : IEnumerator<IAetheryteEntry>
{
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()

View file

@ -141,7 +141,7 @@ internal sealed partial class BuddyList
private struct Enumerator(BuddyList buddyList) : IEnumerator<IBuddyMember>
{
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()

View file

@ -115,7 +115,7 @@ internal sealed partial class FateTable
private struct Enumerator(FateTable fateTable) : IEnumerator<IFate>
{
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()

View file

@ -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()
{

View file

@ -143,7 +143,7 @@ internal sealed partial class PartyList
private struct Enumerator(PartyList partyList) : IEnumerator<IPartyMember>
{
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()

View file

@ -153,7 +153,7 @@ public sealed partial class StatusList : IReadOnlyCollection<IStatus>, ICollecti
private struct Enumerator(StatusList statusList) : IEnumerator<IStatus>
{
private int index = 0;
private int index = -1;
public IStatus Current { get; private set; }
@ -161,9 +161,7 @@ public sealed partial class StatusList : IReadOnlyCollection<IStatus>, 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<IStatus>, ICollecti
}
}
this.Current = default;
return false;
}
public void Reset()
{
this.index = 0;
this.index = -1;
}
public void Dispose()