Skip to content

Replace CollectionsMarshal.AsSpan with IList<T> indexing in ToFastArray - #664

Merged
imperugo merged 2 commits into
imperugo:masterfrom
LeaFrock:issue660
Aug 7, 2026
Merged

Replace CollectionsMarshal.AsSpan with IList<T> indexing in ToFastArray#664
imperugo merged 2 commits into
imperugo:masterfrom
LeaFrock:issue660

Conversation

@LeaFrock

@LeaFrock LeaFrock commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Closes #660.

Changes

  • Replace CollectionsMarshal.AsSpan with IList<T> indexing in ToFastArray(ICollection<TSource>? source)
  • Move SpanExtensions.ToFastArray(ReadOnlySpan<TSource> source) to GenericsExtensions
  • Remove GenericsExtensions.ToFastArray(T[]? source) when the ROS overload is enough
  • Move GenericsExtensions from Helpers to Extensions folder & namespace

Checklist

  • Code compiles without warnings (TreatWarningsAsErrors is enabled)
  • Tests pass locally (dotnet test)
  • New code has test coverage
  • No breaking changes to public API (or documented in PR description)

@imperugo

imperugo commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Thanks @LeaFrock. The change itself is right and I've verified the edge case I was most worried about: a null array still returns an empty result on both paths — through ReadOnlySpan<T> (null array converts to an empty span) and through ICollection<T> (the is not { Count: > 0 } pattern covers null). Behaviour is unchanged, and since both GenericsExtensions and SpanExtensions are internal, the namespace move breaks nothing for consumers.

I pushed a merge commit to this branch — here's why.

The PR was showing 2712 changed lines in CacheClientTestBase.cs for what is actually a two-line using change. The file was being converted from CRLF to LF wholesale, which buried the real change and would have wiped git blame for a 1357-line test file.

That wasn't your doing. The repo had no .gitattributes and mixed line endings — 16 files were CRLF, the other ~100 LF — so whoever touches one of those files from a different platform flips the whole thing. It was going to keep happening to every contributor.

So I fixed the cause on master first (9d6f6d6): added a .gitattributes normalizing to LF in the repository and native in the working tree, with .bat/.cmd/.ps1/.sln pinned to CRLF and .sh to LF, then ran git add --renormalize .. Purely mechanical — git diff -w --ignore-cr-at-eol is empty across all 18 touched files.

Then I merged that master into this branch. The only conflict was the using block in CacheClientTestBase.cs, which I resolved in favour of your version (Core.HelpersCore.Extensions, and dropping the redundant using StackExchange.Redis; — the test namespace nests under it, so it resolves without).

Result: the diff went from +1408/-1444 to +54/-90, and CacheClientTestBase.cs is now 4 lines instead of 2712. Nothing else changed. Please git pull before your next commit on this branch.

Verified locally after the merge: clean build on all TFMs with TreatWarningsAsErrors, and 1754 + 26 tests green on net10.0 (two consecutive full runs).

One observation while I was in there, unrelated to this PR: AddAsyncDateTimeOffset_WithTags_CorrectTaggedKey_Async passes in the full suite but fails when run in isolation with --filter, so it depends on state left by earlier tests. That's pre-existing on master, not something you introduced — I'll open a separate issue.

Ready to merge from my side. It ships with v13.5.

@imperugo

imperugo commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Merging. Thanks @LeaFrock — this ships in v13.5.

@imperugo
imperugo merged commit d6bf654 into imperugo:master Aug 7, 2026
4 checks passed
@LeaFrock
LeaFrock deleted the issue660 branch August 8, 2026 06:05
@imperugo imperugo mentioned this pull request Aug 10, 2026
4 tasks
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.

Replace CollectionsMarshal.AsSpan with IList<T> indexing in ToFastArray

2 participants