@@ -36,6 +36,8 @@ public class TrackCircuitState
3636 public int RemoteReserved ; // remote reserved (number only) //
3737 public bool Forced ; // forced by human dispatcher //
3838
39+ List < Train . TrainRouted > TrainOccupyList ; // used for allocation-free returning of the TrainOccuping() result //
40+
3941 public TrackCircuitState ( )
4042 {
4143 TrainOccupy = new TrainOccupyState ( ) ;
@@ -253,12 +255,13 @@ public void Save(BinaryWriter outf)
253255 /// </summary>
254256 public List < Train . TrainRouted > TrainsOccupying ( )
255257 {
256- List < Train . TrainRouted > reqList = new List < Train . TrainRouted > ( ) ;
258+ TrainOccupyList = TrainOccupyList ?? new List < Train . TrainRouted > ( ) ;
259+ TrainOccupyList . Clear ( ) ;
257260 foreach ( KeyValuePair < Train . TrainRouted , int > thisTCT in TrainOccupy )
258261 {
259- reqList . Add ( thisTCT . Key ) ;
262+ TrainOccupyList . Add ( thisTCT . Key ) ;
260263 }
261- return ( reqList ) ;
264+ return ( TrainOccupyList ) ;
262265 }
263266
264267 /// <summary>
@@ -267,15 +270,16 @@ public void Save(BinaryWriter outf)
267270 /// </summary>
268271 public List < Train . TrainRouted > TrainsOccupying ( int reqDirection )
269272 {
270- List < Train . TrainRouted > reqList = new List < Train . TrainRouted > ( ) ;
273+ TrainOccupyList = TrainOccupyList ?? new List < Train . TrainRouted > ( ) ;
274+ TrainOccupyList . Clear ( ) ;
271275 foreach ( KeyValuePair < Train . TrainRouted , int > thisTCT in TrainOccupy )
272276 {
273277 if ( thisTCT . Value == reqDirection )
274278 {
275- reqList . Add ( thisTCT . Key ) ;
279+ TrainOccupyList . Add ( thisTCT . Key ) ;
276280 }
277281 }
278- return ( reqList ) ;
282+ return ( TrainOccupyList ) ;
279283 }
280284
281285 /// <summary>
0 commit comments