@@ -283,14 +283,16 @@ public void Remove<T>(in Entity entity)
283283 public void Playback ( World world , bool dispose = true )
284284 {
285285 // Create recorded entities.
286+ int createCount = Creates . Count ;
286287 foreach ( var cmd in Creates )
287288 {
288289 var entity = world . Create ( cmd . Types ) ;
289290 Entities [ cmd . Index ] = entity ;
290291 }
291292
292293 // 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 ++ )
294296 {
295297 var wrappedEntity = Adds . Entities [ index ] ;
296298 for ( var i = 0 ; i < Adds . UsedSize ; i ++ )
@@ -320,7 +322,8 @@ public void Playback(World world, bool dispose = true)
320322 }
321323
322324 // 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 ++ )
324327 {
325328 // Get wrapped entity
326329 var wrappedEntity = Sets . Entities [ index ] ;
@@ -364,7 +367,8 @@ public void Playback(World world, bool dispose = true)
364367 }
365368
366369 // 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 ++ )
368372 {
369373 var wrappedEntity = Removes . Entities [ index ] ;
370374 for ( var i = 0 ; i < Removes . UsedSize ; i ++ )
@@ -392,6 +396,7 @@ public void Playback(World world, bool dispose = true)
392396 }
393397
394398 // Play back destructions.
399+ int destroyCount = Destroys . Count ;
395400 foreach ( var cmd in Destroys )
396401 {
397402 world . Destroy ( Entities [ cmd ] ) ;
@@ -406,11 +411,26 @@ public void Playback(World world, bool dispose = true)
406411 Size = 0 ;
407412 Entities . Clear ( ) ;
408413 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+ }
414434 _addTypes . Clear ( ) ;
415435 _removeTypes . Clear ( ) ;
416436 }
0 commit comments