Skip to content

Replace some Lists that used Base() with raw arrays - #201

Merged
marchc1 merged 13 commits into
SourceDotNET:mainfrom
ZehMatt:map-data-arrays
Oct 16, 2026
Merged

marchc1 merged 13 commits into
SourceDotNET:mainfrom
ZehMatt:map-data-arrays

Conversation

@ZehMatt

@ZehMatt ZehMatt commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

This kills the need of a Base() function which emitted IL, I've added a new utility struct SpanList that works like List on an existing allocated array to avoid having manual counters, on top of the replacement I did convert one case that had this pattern where it goes arr[counter++] = elem which this little new utility is preventing having to do, as a little side effect of the cleanup Mod_RecomputeTranslucency now holds the 128 elements on stack with InlineArray128 and simplified the use of GetMaterialListFromBodyAndSkin using SpanList. Also some minor code cleanup, Memory compared to Span is heavier also it should use ReadOnlySpan for when something isn't supposed to mutate data.

@marchc1

marchc1 commented Oct 16, 2026

Copy link
Copy Markdown
Member

Starting a review now, but as far as getting rid of IL while keeping Base(), we could've used https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafeaccessorattribute?view=net-10.0, iirc I just didn't know about it at the time

@ZehMatt

ZehMatt commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

Starting a review now, but as far as getting rid of IL while keeping Base(), we could've used https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafeaccessorattribute?view=net-10.0, iirc I just didn't know about it at the time

We could have but accessing private members is sort of discouraged to do, there is no need to have a Base when just plain arrays solve this with no overhead, no additional code, expresses exactly what its doing.

@marchc1

marchc1 commented Oct 16, 2026

Copy link
Copy Markdown
Member

agreed, just was saying it was silly of me to even use the dynamic IL in the first place

@marchc1 marchc1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a huge nitpick but this is the only thing I noticed

Comment thread Source.Common/Utilities/SpanList.cs Outdated
marchc1
marchc1 previously approved these changes Oct 16, 2026
@marchc1
marchc1 merged commit 017ad84 into SourceDotNET:main Oct 16, 2026
4 checks passed
@ZehMatt
ZehMatt deleted the map-data-arrays branch October 16, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants