Skip to content

refactor: tighten hand-written plumbing (ScopedAllocator/UnsafeUtils)#18

Merged
tinysec merged 1 commit into
masterfrom
refactor/plumbing-maintainability
Jul 7, 2026
Merged

refactor: tighten hand-written plumbing (ScopedAllocator/UnsafeUtils)#18
tinysec merged 1 commit into
masterfrom
refactor/plumbing-maintainability

Conversation

@tinysec

@tinysec tinysec commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Three maintainability fixes in the hand-written marshaling layer, all behavior-preserving (25/25 E2E green alongside the other open PRs):

  • ScopedAllocator.AllocIntegerArray<T> allocated IntPtr.Size bytes per element but wrote at elementSize stride, so uint[] (BNRegisterSetWithConfidence) over-allocated 2× and byte[] 8×. Now strides by Marshal.SizeOf<T>(), matching the element-sized allocation already used by AllocStructArray.
  • ScopedAllocator: bare throw new ExceptionNotSupportedException for the unsupported-element-type guards.
  • 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.

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.
@tinysec tinysec merged commit 2aa4309 into master Jul 7, 2026
1 check passed
@tinysec tinysec deleted the refactor/plumbing-maintainability branch July 7, 2026 09:58
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.

1 participant