From d0199403995790b18e2b8a5c7a165efce525b063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 16 Jun 2026 17:20:22 +0200 Subject: [PATCH] perf: simplify Memory.HasCount to avoid unnecessary ReadOnlyMemory cast The Memory overload of Assert.HasCount was using ((ReadOnlyMemory)collection).Span to forward to the private ReadOnlySpan overload. The intermediate cast to ReadOnlyMemory is unnecessary: Memory.Span returns Span, which is implicitly convertible to ReadOnlySpan when the compiler resolves the private method call. This matches the pattern used by the ReadOnlyMemory overload directly above it: => HasCount(nameof(HasCount), expected, collection.Span, message, collectionExpression); No behavior change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/TestFramework/TestFramework/Assertions/Assert.Count.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs index 0261c40212..10066e3112 100644 --- a/src/TestFramework/TestFramework/Assertions/Assert.Count.cs +++ b/src/TestFramework/TestFramework/Assertions/Assert.Count.cs @@ -587,7 +587,7 @@ public static void HasCount(int expected, Memory collection, [Interpolated /// Users shouldn't pass a value for this parameter. /// public static void HasCount(int expected, Memory collection, string? message = "", [CallerArgumentExpression(nameof(collection))] string collectionExpression = "") - => HasCount(nameof(HasCount), expected, ((ReadOnlyMemory)collection).Span, message, collectionExpression); + => HasCount(nameof(HasCount), expected, collection.Span, message, collectionExpression); #endif