Skip to content

Commit d52e479

Browse files
teinarssabcdefg30
authored andcommitted
Refactor classes to structs
1 parent 544ac6c commit d52e479

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

OpenRA.Game/Map/CellRegion.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ IEnumerator IEnumerable.GetEnumerator()
117117
return GetEnumerator();
118118
}
119119

120-
public sealed class CellRegionEnumerator : IEnumerator<CPos>
120+
public struct CellRegionEnumerator : IEnumerator<CPos>
121121
{
122122
readonly CellRegion r;
123123

@@ -128,9 +128,11 @@ public sealed class CellRegionEnumerator : IEnumerator<CPos>
128128
CPos current;
129129

130130
public CellRegionEnumerator(CellRegion region)
131+
: this()
131132
{
132133
r = region;
133134
Reset();
135+
current = new MPos(u, v).ToCPos(r.gridType);
134136
}
135137

136138
public bool MoveNext()

OpenRA.Game/Map/ProjectedCellRegion.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ IEnumerator IEnumerable.GetEnumerator()
7676
return GetEnumerator();
7777
}
7878

79-
public sealed class ProjectedCellRegionEnumerator : IEnumerator<PPos>
79+
public struct ProjectedCellRegionEnumerator : IEnumerator<PPos>
8080
{
8181
readonly ProjectedCellRegion r;
8282

@@ -86,9 +86,11 @@ public sealed class ProjectedCellRegionEnumerator : IEnumerator<PPos>
8686
PPos current;
8787

8888
public ProjectedCellRegionEnumerator(ProjectedCellRegion region)
89+
: this()
8990
{
9091
r = region;
9192
Reset();
93+
current = new PPos(u, v);
9294
}
9395

9496
public bool MoveNext()

OpenRA.Game/TraitDictionary.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,14 @@ class MultipleEnumerable : IEnumerable<T>
179179
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
180180
}
181181

182-
class MultipleEnumerator : IEnumerator<T>
182+
struct MultipleEnumerator : IEnumerator<T>
183183
{
184184
readonly List<Actor> actors;
185185
readonly List<T> traits;
186186
readonly uint actor;
187187
int index;
188188
public MultipleEnumerator(TraitContainer<T> container, uint actor)
189+
: this()
189190
{
190191
actors = container.actors;
191192
traits = container.traits;
@@ -236,20 +237,21 @@ public IEnumerable<Actor> Actors(Func<T, bool> predicate)
236237
}
237238
}
238239

239-
class AllEnumerable : IEnumerable<TraitPair<T>>
240+
struct AllEnumerable : IEnumerable<TraitPair<T>>
240241
{
241242
readonly TraitContainer<T> container;
242243
public AllEnumerable(TraitContainer<T> container) { this.container = container; }
243244
public IEnumerator<TraitPair<T>> GetEnumerator() { return new AllEnumerator(container); }
244245
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
245246
}
246247

247-
class AllEnumerator : IEnumerator<TraitPair<T>>
248+
struct AllEnumerator : IEnumerator<TraitPair<T>>
248249
{
249250
readonly List<Actor> actors;
250251
readonly List<T> traits;
251252
int index;
252253
public AllEnumerator(TraitContainer<T> container)
254+
: this()
253255
{
254256
actors = container.actors;
255257
traits = container.traits;

OpenRA.Mods.Common/Traits/World/ActorMap.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,29 +216,40 @@ void INotifyCreated.Created(Actor self)
216216
}
217217
}
218218

219-
sealed class ActorsAtEnumerator : IEnumerator<Actor>
219+
struct ActorsAtEnumerator : IEnumerator<Actor>
220220
{
221221
InfluenceNode node;
222-
public ActorsAtEnumerator(InfluenceNode node) { this.node = node; }
222+
Actor current;
223+
224+
public ActorsAtEnumerator(InfluenceNode node)
225+
{
226+
this.node = node;
227+
current = null;
228+
}
229+
223230
public void Reset() { throw new NotSupportedException(); }
224-
public Actor Current { get; private set; }
225-
object IEnumerator.Current { get { return Current; } }
231+
public Actor Current
232+
{
233+
get { return current; }
234+
}
235+
236+
object IEnumerator.Current { get { return current; } }
226237
public void Dispose() { }
227238
public bool MoveNext()
228239
{
229240
while (node != null)
230241
{
231-
Current = node.Actor;
242+
current = node.Actor;
232243
node = node.Next;
233-
if (!Current.Disposed)
244+
if (!current.Disposed)
234245
return true;
235246
}
236247

237248
return false;
238249
}
239250
}
240251

241-
sealed class ActorsAtEnumerable : IEnumerable<Actor>
252+
struct ActorsAtEnumerable : IEnumerable<Actor>
242253
{
243254
readonly InfluenceNode node;
244255
public ActorsAtEnumerable(InfluenceNode node) { this.node = node; }

0 commit comments

Comments
 (0)