Skip to content

Avoid List<T> allocation in Assert.ContainsSingle<T>#7537

Merged
Evangelink merged 1 commit intomainfrom
dev/amauryleve/contains
Mar 12, 2026
Merged

Avoid List<T> allocation in Assert.ContainsSingle<T>#7537
Evangelink merged 1 commit intomainfrom
dev/amauryleve/contains

Conversation

@Evangelink
Copy link
Member

Replace .Where(predicate).ToList() with a manual foreach loop that counts matches and captures the first one. This avoids allocating a List on every call. The non-generic overload already used this pattern.

Replace .Where(predicate).ToList() with a manual foreach loop that counts matches and captures the first one. This avoids allocating a List<T> on every call. The non-generic overload already used this pattern.
Copilot AI review requested due to automatic review settings March 12, 2026 15:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Replaces a LINQ .Where(predicate).ToList() allocation in Assert.ContainsSingle<T> with a manual foreach loop, matching the pattern already used by the non-generic overload.

Changes:

  • Replace LINQ-based filtering with a manual loop that counts matches and captures the first one, avoiding a List<T> allocation.

You can also share your feedback on Copilot code review. Take the survey.

@Evangelink Evangelink enabled auto-merge March 12, 2026 15:40
@Evangelink Evangelink merged commit 68290eb into main Mar 12, 2026
15 checks passed
@Evangelink Evangelink deleted the dev/amauryleve/contains branch March 12, 2026 16:37
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.

3 participants