refactor: tighten hand-written plumbing (ScopedAllocator/UnsafeUtils)#18
Merged
Conversation
Three maintainability fixes in the hand-written marshaling layer, all behavior-preserving (24/24 E2E green alongside the navigation extensions): ScopedAllocator.AllocIntegerArray<T> allocated IntPtr.Size bytes per element but wrote at elementSize stride, so uint[] (BNRegisterSetWithConfidence) over- allocated 2x and byte[] 8x. Now strides by Marshal.SizeOf<T>(), matching the element-sized allocation already used by AllocStructArray. ScopedAllocator: bare 'throw new Exception' -> NotSupportedException for the unsupported-element-type guards (more specific exception type). UnsafeUtils.ReadNumber: the float/double branches allocated a byte[], Marshal.Copy into it, then BitConverter. Replaced with Unsafe.ReadUnaligned (allocation-free, AOT-safe, identical IEEE bit pattern), matching the enum branch already there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three maintainability fixes in the hand-written marshaling layer, all behavior-preserving (25/25 E2E green alongside the other open PRs):
ScopedAllocator.AllocIntegerArray<T>allocatedIntPtr.Sizebytes per element but wrote atelementSizestride, souint[](BNRegisterSetWithConfidence) over-allocated 2× andbyte[]8×. Now strides byMarshal.SizeOf<T>(), matching the element-sized allocation already used byAllocStructArray.ScopedAllocator: barethrow new Exception→NotSupportedExceptionfor the unsupported-element-type guards.UnsafeUtils.ReadNumber: thefloat/doublebranches allocated abyte[],Marshal.Copyinto it, thenBitConverter. Replaced withUnsafe.ReadUnaligned(allocation-free, AOT-safe, identical IEEE bit pattern), matching theenumbranch already there.