Skip to content

Commit e4cf920

Browse files
authored
remove unnecessary list alloc for 2 scenarios in TestRequestManager.GetSources (#5058)
1 parent 4668769 commit e4cf920

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/vstest.console/TestPlatformHelpers/TestRequestManager.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,23 +1510,21 @@ private IRequestData GetRequestData(ProtocolConfig protocolConfig)
15101510
private static List<string> GetSources(TestRunRequestPayload testRunRequestPayload)
15111511
{
15121512
// TODO: This should also use hashset to only return distinct sources.
1513-
List<string> sources = new();
1514-
if (testRunRequestPayload.Sources != null
1515-
&& testRunRequestPayload.Sources.Count > 0)
1513+
if (testRunRequestPayload.Sources is { Count: > 0 })
15161514
{
1517-
sources = testRunRequestPayload.Sources;
1515+
return testRunRequestPayload.Sources;
15181516
}
1519-
else if (testRunRequestPayload.TestCases != null
1520-
&& testRunRequestPayload.TestCases.Count > 0)
1517+
1518+
if (testRunRequestPayload.TestCases is { Count: > 0 })
15211519
{
1522-
ISet<string> sourcesSet = new HashSet<string>();
1520+
var sourcesSet = new HashSet<string>();
15231521
foreach (var testCase in testRunRequestPayload.TestCases)
15241522
{
15251523
sourcesSet.Add(testCase.Source);
15261524
}
1527-
sources = sourcesSet.ToList();
1525+
return sourcesSet.ToList();
15281526
}
1529-
return sources;
1527+
return [];
15301528
}
15311529
}
15321530

0 commit comments

Comments
 (0)