Skip to content

Commit

Permalink
remove unnecessary list alloc for 2 scenarios in TestRequestManager.G…
Browse files Browse the repository at this point in the history
…etSources (#5058)
  • Loading branch information
SimonCropp authored May 23, 2024
1 parent 4668769 commit e4cf920
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1510,23 +1510,21 @@ private IRequestData GetRequestData(ProtocolConfig protocolConfig)
private static List<string> GetSources(TestRunRequestPayload testRunRequestPayload)
{
// TODO: This should also use hashset to only return distinct sources.
List<string> sources = new();
if (testRunRequestPayload.Sources != null
&& testRunRequestPayload.Sources.Count > 0)
if (testRunRequestPayload.Sources is { Count: > 0 })
{
sources = testRunRequestPayload.Sources;
return testRunRequestPayload.Sources;
}
else if (testRunRequestPayload.TestCases != null
&& testRunRequestPayload.TestCases.Count > 0)

if (testRunRequestPayload.TestCases is { Count: > 0 })
{
ISet<string> sourcesSet = new HashSet<string>();
var sourcesSet = new HashSet<string>();
foreach (var testCase in testRunRequestPayload.TestCases)
{
sourcesSet.Add(testCase.Source);
}
sources = sourcesSet.ToList();
return sourcesSet.ToList();
}
return sources;
return [];
}
}

Expand Down

0 comments on commit e4cf920

Please sign in to comment.