@@ -36,6 +36,8 @@ public class TrackCircuitState
36
36
public int RemoteReserved ; // remote reserved (number only) //
37
37
public bool Forced ; // forced by human dispatcher //
38
38
39
+ List < Train . TrainRouted > TrainOccupyList ; // used for allocation-free returning of the TrainOccuping() result //
40
+
39
41
public TrackCircuitState ( )
40
42
{
41
43
TrainOccupy = new TrainOccupyState ( ) ;
@@ -253,12 +255,13 @@ public void Save(BinaryWriter outf)
253
255
/// </summary>
254
256
public List < Train . TrainRouted > TrainsOccupying ( )
255
257
{
256
- List < Train . TrainRouted > reqList = new List < Train . TrainRouted > ( ) ;
258
+ TrainOccupyList = TrainOccupyList ?? new List < Train . TrainRouted > ( ) ;
259
+ TrainOccupyList . Clear ( ) ;
257
260
foreach ( KeyValuePair < Train . TrainRouted , int > thisTCT in TrainOccupy )
258
261
{
259
- reqList . Add ( thisTCT . Key ) ;
262
+ TrainOccupyList . Add ( thisTCT . Key ) ;
260
263
}
261
- return ( reqList ) ;
264
+ return ( TrainOccupyList ) ;
262
265
}
263
266
264
267
/// <summary>
@@ -267,15 +270,16 @@ public void Save(BinaryWriter outf)
267
270
/// </summary>
268
271
public List < Train . TrainRouted > TrainsOccupying ( int reqDirection )
269
272
{
270
- List < Train . TrainRouted > reqList = new List < Train . TrainRouted > ( ) ;
273
+ TrainOccupyList = TrainOccupyList ?? new List < Train . TrainRouted > ( ) ;
274
+ TrainOccupyList . Clear ( ) ;
271
275
foreach ( KeyValuePair < Train . TrainRouted , int > thisTCT in TrainOccupy )
272
276
{
273
277
if ( thisTCT . Value == reqDirection )
274
278
{
275
- reqList . Add ( thisTCT . Key ) ;
279
+ TrainOccupyList . Add ( thisTCT . Key ) ;
276
280
}
277
281
}
278
- return ( reqList ) ;
282
+ return ( TrainOccupyList ) ;
279
283
}
280
284
281
285
/// <summary>
0 commit comments