refactor: Use CollectionsMarshal.SetCount to resize lists#2945
refactor: Use CollectionsMarshal.SetCount to resize lists#2945Eideren merged 1 commit intostride3d:masterfrom
Conversation
Makes code easier to read (as it was before a122c71). The SetCount implementation looks very similar to the previously used Resize method of FastList. For value types it just sets the internal count, for reference types it clears the pointers. Both what was done before as well.
|
Does it zero the new data? If not that's a behavioral change. I can only assume that the code that was explicitly clearing the data was here for a reason. And if it is not needed, it should be documented in the code why. |
|
It seems that if it is going to shrink, and the type is a reference type or contains references, it clears. You can see it here. If it needs to grow the list, it does a For value types that don't contain references, it does nothing to them (so they can expose stale data). |
|
On second read it looks fine. Thanks. |
|
What @Ethereal77 said - for value types stale data could be observed. But only the third case (RenderSystem) in this commit is about value types and when we read a few lines further down each entry in the re-sized list gets written (no read). |
|
Thanks ! |
PR Details
Makes code easier to read (as it was before a122c71). The SetCount implementation looks very similar to the previously used Resize method of FastList. For value types it just sets the internal count, for reference types it clears the pointers. Both what was done before as well.
Related Issue
Types of changes
Checklist