Skip to content

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.

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.

3 participants