genaray / Arch.Extended

Extensions for Arch with some useful features like Systems, Source Generator and Utils.
Apache License 2.0
151 stars 35 forks source link

Unsafe List Indexers Bounds Checks #37

Closed martindevans closed 11 months ago

martindevans commented 11 months ago

Added test coverage to the UnsafeList indexers.

Also added bounds checking to the indexers. Two methods in UnsafeList deliberately access out of bounds (Add and RemoveAt) so I've modified those to go directly to the underlying _array, bypassing the new checks).

I considered wrapping the checks in an #if DEBUG block, so there's no extra cost in release builds. Personally I think it's better to keep the checks, but that's an option if you'd prefer that? (This is now done).

genaray commented 11 months ago

I would prefer to Wrap them into preprocessor variables since branching comes with an overhead. And the whole Point of those unsafe collections is being fast ^^

martindevans commented 11 months ago

I've added a preprocessor block around the checks and inlined the CheckIndex method for good measure.

genaray commented 11 months ago

btw are you in the discord? If so ill make you a contributor there ^^

martindevans commented 11 months ago

I just joined, I'm martindevans on Discord too.