From d518c428a2075e1b5d04032a3e6c1692ff2a3de2 Mon Sep 17 00:00:00 2001 From: Timothy Makkison Date: Fri, 16 Jan 2026 00:39:43 +0000 Subject: [PATCH] perf: add capacity to `StringBuilder` in `ValueAssertion` --- TUnit.Assertions/Sources/ValueAssertion.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/TUnit.Assertions/Sources/ValueAssertion.cs b/TUnit.Assertions/Sources/ValueAssertion.cs index a17d8ed7e9..b6ce07b451 100644 --- a/TUnit.Assertions/Sources/ValueAssertion.cs +++ b/TUnit.Assertions/Sources/ValueAssertion.cs @@ -15,7 +15,8 @@ public class ValueAssertion : IAssertionSource public ValueAssertion(TValue? value, string? expression) { - var expressionBuilder = new StringBuilder(); + // Initialize StringBuilder with enough space for expression and text + var expressionBuilder = new StringBuilder((expression?.Length ?? 1) + 32); expressionBuilder.Append($"Assert.That({expression ?? "?"})"); Context = new AssertionContext(value, expressionBuilder); }