Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -289,12 +289,14 @@ private static bool TryUnfoldITestDataSource(ITestDataSource dataSource, UnitTes

var discoveredTests = new List<UnitTestElement>();
bool dataSourceHasData = false;
// PERF: Hoist outside the loop — MethodInfo.GetParameters() returns a fresh array copy on each
// call (CLR safety guarantee), so calling it per row allocates N identical arrays for N data rows.
ParameterInfo[] parameters = methodInfo.GetParameters();

foreach (object?[] dataOrTestDataRow in dataEnumerable)
{
dataSourceHasData = true;
object?[] d = dataOrTestDataRow;
ParameterInfo[] parameters = methodInfo.GetParameters();

// The effective ignore message for this row is the row-level ignore message (from
// TestDataRow<T>), falling back to the whole-source ignore message. It must be
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,7 +60,17 @@ internal ITestContext TestContext
/// <summary>
/// Gets the parameter types of the test method.
/// </summary>
public ParameterInfo[] ParameterTypes => MethodInfo.GetParameters();
/// <remarks>
/// Lazy-cached: <c>MethodInfo.GetParameters()</c> returns a fresh array copy on every call
/// (CLR safety guarantee), so caching avoids N redundant copies for data-driven tests with N rows.
/// This cached array is shared across internal call sites and MUST NOT be mutated. The explicit
/// <see cref="ITestMethod.ParameterTypes"/> implementation hands external consumers a fresh copy to
/// preserve the previous "fresh array per call" behavior and protect the cache from mutation.
/// </remarks>
public ParameterInfo[] ParameterTypes => field ??= MethodInfo.GetParameters();

/// <inheritdoc />
ParameterInfo[] ITestMethod.ParameterTypes => (ParameterInfo[])ParameterTypes.Clone();

/// <summary>
/// Gets the return type of the test method.
Expand Down