Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use List<T>.RemoveAll in System.Management.Automation.ModuleIntrinsics #15686

Merged
merged 4 commits into from
Jul 8, 2021

Conversation

xtqqczze
Copy link
Contributor

Save allocation of temporary lists.

@ghost ghost assigned daxian-dbw Jun 29, 2021
@iSazonov iSazonov added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Jun 29, 2021
@daxian-dbw
Copy link
Member

@xtqqczze I made a slight change to remove the 'firstTime' variable. Please take a look and see if you have any concerns.

output.Add(item);
}

bool match = previousKey != null && currentKey.Equals(previousKey, StringComparison.OrdinalIgnoreCase);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if item-s is null? Second null will be not removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my thought, but this is private code, and keyGetter never returns null in practice.

I think it would be best to add null annotations and maybe a Debug.Assert.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be best to add null annotations

We're doing it at such a rate that it will take us a hundred years to finish the job. 😸
Adding #nullable enable locally add no value and doesn't protect from errors coming from highest level of code.
Debug.Assert assumes we cover the code fully by tests but we don't run tests on Debug build at all.

Nevertheless I'd agree with local #nullable enable if we add a comment that sessionState.ExportedFunctions, sessionState.Module.CompiledExports, sessionState.ExportedVariables and sessionState.ExportedAliases do not contain nulls by design.

@xtqqczze
Copy link
Contributor Author

xtqqczze commented Jul 5, 2021

@daxian-dbw I've pushed some minor changes.

@@ -1438,7 +1438,7 @@ internal static void RemoveNestedModuleFunctions(PSModuleInfo module)
#nullable enable
private static void SortAndRemoveDuplicates<T>(List<T> input, Func<T, string> keyGetter)
{
Dbg.Assert(input != null, "Caller should verify that input != null");
Dbg.Assert(input is not null, "Caller should verify that input != null");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove - we said about null items in the List.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I would update the code style while touching the method.

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@daxian-dbw daxian-dbw merged commit 6d08db6 into PowerShell:master Jul 8, 2021
@daxian-dbw daxian-dbw added this to the 7.2.0-preview.8 milestone Jul 8, 2021
@ghost
Copy link

ghost commented Jul 22, 2021

🎉v7.2.0-preview.8 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants