mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-02 05:43:40 +01:00
Better enumerator code
This commit is contained in:
parent
2e7c48316f
commit
1c1b60efee
6 changed files with 46 additions and 34 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue