Refactor classes to structs

This commit is contained in:
teinarss
2020-07-06 20:27:24 +02:00
committed by abcdefg30
parent 544ac6cb33
commit d52e4793fe
4 changed files with 29 additions and 12 deletions

View File

@@ -117,7 +117,7 @@ namespace OpenRA
return GetEnumerator();
}
public sealed class CellRegionEnumerator : IEnumerator<CPos>
public struct CellRegionEnumerator : IEnumerator<CPos>
{
readonly CellRegion r;
@@ -128,9 +128,11 @@ namespace OpenRA
CPos current;
public CellRegionEnumerator(CellRegion region)
: this()
{
r = region;
Reset();
current = new MPos(u, v).ToCPos(r.gridType);
}
public bool MoveNext()

View File

@@ -76,7 +76,7 @@ namespace OpenRA
return GetEnumerator();
}
public sealed class ProjectedCellRegionEnumerator : IEnumerator<PPos>
public struct ProjectedCellRegionEnumerator : IEnumerator<PPos>
{
readonly ProjectedCellRegion r;
@@ -86,9 +86,11 @@ namespace OpenRA
PPos current;
public ProjectedCellRegionEnumerator(ProjectedCellRegion region)
: this()
{
r = region;
Reset();
current = new PPos(u, v);
}
public bool MoveNext()

View File

@@ -179,13 +179,14 @@ namespace OpenRA
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
class MultipleEnumerator : IEnumerator<T>
struct MultipleEnumerator : IEnumerator<T>
{
readonly List<Actor> actors;
readonly List<T> traits;
readonly uint actor;
int index;
public MultipleEnumerator(TraitContainer<T> container, uint actor)
: this()
{
actors = container.actors;
traits = container.traits;
@@ -236,7 +237,7 @@ namespace OpenRA
}
}
class AllEnumerable : IEnumerable<TraitPair<T>>
struct AllEnumerable : IEnumerable<TraitPair<T>>
{
readonly TraitContainer<T> container;
public AllEnumerable(TraitContainer<T> container) { this.container = container; }
@@ -244,12 +245,13 @@ namespace OpenRA
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
class AllEnumerator : IEnumerator<TraitPair<T>>
struct AllEnumerator : IEnumerator<TraitPair<T>>
{
readonly List<Actor> actors;
readonly List<T> traits;
int index;
public AllEnumerator(TraitContainer<T> container)
: this()
{
actors = container.actors;
traits = container.traits;

View File

@@ -216,21 +216,32 @@ namespace OpenRA.Mods.Common.Traits
}
}
sealed class ActorsAtEnumerator : IEnumerator<Actor>
struct ActorsAtEnumerator : IEnumerator<Actor>
{
InfluenceNode node;
public ActorsAtEnumerator(InfluenceNode node) { this.node = node; }
Actor current;
public ActorsAtEnumerator(InfluenceNode node)
{
this.node = node;
current = null;
}
public void Reset() { throw new NotSupportedException(); }
public Actor Current { get; private set; }
object IEnumerator.Current { get { return Current; } }
public Actor Current
{
get { return current; }
}
object IEnumerator.Current { get { return current; } }
public void Dispose() { }
public bool MoveNext()
{
while (node != null)
{
Current = node.Actor;
current = node.Actor;
node = node.Next;
if (!Current.Disposed)
if (!current.Disposed)
return true;
}
@@ -238,7 +249,7 @@ namespace OpenRA.Mods.Common.Traits
}
}
sealed class ActorsAtEnumerable : IEnumerable<Actor>
struct ActorsAtEnumerable : IEnumerable<Actor>
{
readonly InfluenceNode node;
public ActorsAtEnumerable(InfluenceNode node) { this.node = node; }