@@ -283,14 +283,16 @@ public void Remove<T>(in Entity entity)
283
283
public void Playback ( World world , bool dispose = true )
284
284
{
285
285
// Create recorded entities.
286
+ int createCount = Creates . Count ;
286
287
foreach ( var cmd in Creates )
287
288
{
288
289
var entity = world . Create ( cmd . Types ) ;
289
290
Entities [ cmd . Index ] = entity ;
290
291
}
291
292
292
293
// Play back additions.
293
- for ( var index = 0 ; index < Adds . Count ; index ++ )
294
+ int addCount = Adds . Count ;
295
+ for ( var index = 0 ; index < addCount ; index ++ )
294
296
{
295
297
var wrappedEntity = Adds . Entities [ index ] ;
296
298
for ( var i = 0 ; i < Adds . UsedSize ; i ++ )
@@ -320,7 +322,8 @@ public void Playback(World world, bool dispose = true)
320
322
}
321
323
322
324
// Play back sets.
323
- for ( var index = 0 ; index < Sets . Count ; index ++ )
325
+ int setCount = Sets . Count ;
326
+ for ( var index = 0 ; index < setCount ; index ++ )
324
327
{
325
328
// Get wrapped entity
326
329
var wrappedEntity = Sets . Entities [ index ] ;
@@ -364,7 +367,8 @@ public void Playback(World world, bool dispose = true)
364
367
}
365
368
366
369
// Play back removals.
367
- for ( var index = 0 ; index < Removes . Count ; index ++ )
370
+ int removeCount = Removes . Count ;
371
+ for ( var index = 0 ; index < removeCount ; index ++ )
368
372
{
369
373
var wrappedEntity = Removes . Entities [ index ] ;
370
374
for ( var i = 0 ; i < Removes . UsedSize ; i ++ )
@@ -392,6 +396,7 @@ public void Playback(World world, bool dispose = true)
392
396
}
393
397
394
398
// Play back destructions.
399
+ int destroyCount = Destroys . Count ;
395
400
foreach ( var cmd in Destroys )
396
401
{
397
402
world . Destroy ( Entities [ cmd ] ) ;
@@ -406,11 +411,26 @@ public void Playback(World world, bool dispose = true)
406
411
Size = 0 ;
407
412
Entities . Clear ( ) ;
408
413
BufferedEntityInfo . Clear ( ) ;
409
- Creates . Clear ( ) ;
410
- Sets . Clear ( ) ;
411
- Adds . Clear ( ) ;
412
- Removes . Clear ( ) ;
413
- Destroys . Clear ( ) ;
414
+ if ( createCount > 0 )
415
+ {
416
+ Creates . Clear ( ) ;
417
+ }
418
+ if ( setCount > 0 )
419
+ {
420
+ Sets . Clear ( ) ;
421
+ }
422
+ if ( addCount > 0 )
423
+ {
424
+ Adds . Clear ( ) ;
425
+ }
426
+ if ( removeCount > 0 )
427
+ {
428
+ Removes . Clear ( ) ;
429
+ }
430
+ if ( destroyCount > 0 )
431
+ {
432
+ Destroys . Clear ( ) ;
433
+ }
414
434
_addTypes . Clear ( ) ;
415
435
_removeTypes . Clear ( ) ;
416
436
}
0 commit comments