Skip to content

Commit bc9fb9a

Browse files
perf: skip List creation in GetDynamicTestAttributes (#4195)
1 parent 6ca43c5 commit bc9fb9a

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

TUnit.Engine/Building/Collectors/AotTestDataCollector.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,17 @@ private Task<TestMetadata> CreateMetadataFromDynamicDiscoveryResult(DynamicDisco
155155

156156
private static Attribute[] GetDynamicTestAttributes(DynamicDiscoveryResult result)
157157
{
158+
if (result.TestClassType == null)
159+
{
160+
return result.Attributes.ToArray();
161+
}
162+
158163
// Merge explicitly provided attributes with inherited class/assembly attributes
159164
// Order matches GetAllAttributes: method-level first (explicit), then class, then assembly
160165
var attributes = new List<Attribute>(result.Attributes);
161166

162-
if (result.TestClassType != null)
163-
{
164-
attributes.AddRange(result.TestClassType.GetCustomAttributes().OfType<Attribute>());
165-
attributes.AddRange(result.TestClassType.Assembly.GetCustomAttributes().OfType<Attribute>());
166-
}
167+
attributes.AddRange(result.TestClassType.GetCustomAttributes());
168+
attributes.AddRange(result.TestClassType.Assembly.GetCustomAttributes());
167169

168170
return attributes.ToArray();
169171
}

TUnit.Engine/Discovery/ReflectionTestDataCollector.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,15 +1932,17 @@ private Task<TestMetadata> CreateMetadataFromDynamicDiscoveryResult(DynamicDisco
19321932

19331933
private static Attribute[] GetDynamicTestAttributes(DynamicDiscoveryResult result)
19341934
{
1935+
if (result.TestClassType == null)
1936+
{
1937+
return result.Attributes.ToArray();
1938+
}
1939+
19351940
// Merge explicitly provided attributes with inherited class/assembly attributes
19361941
// Order matches GetAllAttributes: method-level first (explicit), then class, then assembly
19371942
var attributes = new List<Attribute>(result.Attributes);
19381943

1939-
if (result.TestClassType != null)
1940-
{
1941-
attributes.AddRange(result.TestClassType.GetCustomAttributes().OfType<Attribute>());
1942-
attributes.AddRange(result.TestClassType.Assembly.GetCustomAttributes().OfType<Attribute>());
1943-
}
1944+
attributes.AddRange(result.TestClassType.GetCustomAttributes());
1945+
attributes.AddRange(result.TestClassType.Assembly.GetCustomAttributes());
19441946

19451947
return attributes.ToArray();
19461948
}

0 commit comments

Comments
 (0)