Skip to content

Commit 0630a02

Browse files
authored
Merge pull request #382 from YoRyan/refactor-copyloops
Replace for loops with explicit array copies and comparisons
2 parents 46cea5d + ccbd8f9 commit 0630a02

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

Source/Orts.Formats.Msts/ShapeFile.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,8 +901,7 @@ public prim_state(prim_state copy)
901901
{
902902
flags = copy.flags;
903903
ishader = copy.ishader;
904-
tex_idxs = new int[copy.tex_idxs.Length];
905-
for (var i = 0; i < copy.tex_idxs.Length; ++i) tex_idxs[i] = copy.tex_idxs[i];
904+
tex_idxs = (int[])copy.tex_idxs.Clone();
906905
ZBias = copy.ZBias;
907906
ivtx_state = copy.ivtx_state;
908907
alphatestmode = copy.alphatestmode;
@@ -915,7 +914,7 @@ public bool Matches(prim_state prim_state)
915914
if (flags != prim_state.flags) return false;
916915
if (ishader != prim_state.ishader) return false;
917916
if (tex_idxs.Length != prim_state.tex_idxs.Length) return false;
918-
for (var i = 0; i < tex_idxs.Length; ++i) if (tex_idxs[i] != prim_state.tex_idxs[i]) return false;
917+
if (!tex_idxs.SequenceEqual(prim_state.tex_idxs)) return false;
919918
if (ZBias != prim_state.ZBias) return false;
920919
if (ivtx_state != prim_state.ivtx_state) return false;
921920
if (alphatestmode != prim_state.alphatestmode) return false;
@@ -1246,8 +1245,7 @@ public vertex(vertex copy)
12461245
inormal = copy.inormal;
12471246
Color1 = copy.Color1;
12481247
Color2 = copy.Color2;
1249-
vertex_uvs = new int[copy.vertex_uvs.Length];
1250-
for (var i = 0; i < copy.vertex_uvs.Length; ++i) vertex_uvs[i] = copy.vertex_uvs[i];
1248+
vertex_uvs = (int[])copy.vertex_uvs.Clone();
12511249
}
12521250

12531251
public vertex()
@@ -1268,8 +1266,7 @@ public bool MatchesContent(vertex vertex)
12681266
if (inormal != vertex.inormal) return false;
12691267
if (Color1 != vertex.Color1) return false;
12701268
if (Color2 != vertex.Color2) return false;
1271-
if (vertex_uvs.Length != vertex.vertex_uvs.Length) return false;
1272-
for (var i = 0; i < vertex_uvs.Length; ++i) if (vertex_uvs[i] != vertex.vertex_uvs[i]) return false;
1269+
if (!vertex_uvs.SequenceEqual(vertex.vertex_uvs)) return false;
12731270
return true;
12741271
}
12751272
}

Source/RunActivity/Viewer3D/Shapes.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,10 @@ public SpeedPostShape(Viewer viewer, string path, WorldPosition position, SpeedP
583583
id = SpeedPostObj.GetTrItemID(idlocation);
584584
}
585585
//create the shape primitive
586-
short[] newTList = new short[NumIndices];
587-
for (i = 0; i < NumIndices; i++) newTList[i] = TriangleListIndices[i];
588-
VertexPositionNormalTexture[] newVList = new VertexPositionNormalTexture[NumVertices];
589-
for (i = 0; i < NumVertices; i++) newVList[i] = VertexList[i];
586+
var newTList = new short[NumIndices];
587+
Array.Copy(TriangleListIndices, newTList, NumIndices);
588+
var newVList = new VertexPositionNormalTexture[NumVertices];
589+
Array.Copy(VertexList, newVList, NumVertices);
590590
IndexBuffer IndexBuffer = new IndexBuffer(viewer.GraphicsDevice, typeof(short),
591591
NumIndices, BufferUsage.WriteOnly);
592592
IndexBuffer.SetData(newTList);

0 commit comments

Comments
 (0)