Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Use span-based overloads#11884

Merged
iSazonov merged 3 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
iSazonov:cleanup-use-span-overloadsiSazonov/PowerShell:cleanup-use-span-overloadsCopy head branch name to clipboard
Mar 18, 2020
Merged

Use span-based overloads#11884
iSazonov merged 3 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
iSazonov:cleanup-use-span-overloadsiSazonov/PowerShell:cleanup-use-span-overloadsCopy head branch name to clipboard

Conversation

@iSazonov

@iSazonov iSazonov commented Feb 19, 2020

Copy link
Copy Markdown
Collaborator

PR Summary

  • First commit - Use span-based overloads to reduce allocations.
  • Second commit - Use String.Contains() for readability.

PR Context

PR Checklist

@iSazonov iSazonov added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Feb 19, 2020
@iSazonov iSazonov added this to the 7.1.0-preview.1 milestone Feb 19, 2020
@iSazonov iSazonov requested a review from SteveL-MSFT February 19, 2020 11:07
Comment thread src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/ModuleViewModel.cs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ToString() here results in an allocation, can we just update that method to accept a readonlyspan?

@iSazonov iSazonov Feb 20, 2020

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, it is used then in class ctor-s.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ReadOnlySpan<char> typically is an implicit cast from string, isn't it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@vexx32 No, only string -> ReadOnlySpan

@vexx32 vexx32 Feb 21, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Right, so if the method parameter is currently using string we should be able to change it to ReadOnlySpan<char> and have the implicit cast handle it, shouldn't we? Or am I missing some context here? 🙂

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I missing some context here

CreateParameterWithArgument() passes the string to a constructor so it makes no sense to convert to span here.

@iSazonov

Copy link
Copy Markdown
Collaborator Author

Added new commit.

Comment thread src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/CommandViewModel.cs Outdated
Comment thread src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/CommandViewModel.cs Outdated
Comment thread src/Microsoft.Management.UI.Internal/ShowCommand/ViewModel/CommandViewModel.cs Outdated
@iSazonov iSazonov force-pushed the cleanup-use-span-overloads branch from 2627a51 to 372c510 Compare February 20, 2020 09:16
@iSazonov iSazonov force-pushed the cleanup-use-span-overloads branch from 372c510 to 3e3fad1 Compare March 9, 2020 17:31

@SteveL-MSFT SteveL-MSFT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use multiple statements for better readability, like

var filterSpan = filter.AsSpan(0, filter.Length - 2);
return commandName.AsSpan().Contains(filterSpan, StringComparison.OrdinalIgnoreCase);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@iSazonov iSazonov force-pushed the cleanup-use-span-overloads branch from 3e3fad1 to 5d7aeed Compare March 13, 2020 06:57
@iSazonov iSazonov merged commit b5d4739 into PowerShell:master Mar 18, 2020
@iSazonov iSazonov deleted the cleanup-use-span-overloads branch March 18, 2020 13:39
@ghost

ghost commented Mar 26, 2020

Copy link
Copy Markdown

🎉v7.1.0-preview.1 has been released which incorporates this pull request.:tada:

Handy links:

@iSazonov iSazonov mentioned this pull request Oct 29, 2020
14 tasks
@iSazonov iSazonov mentioned this pull request Jan 3, 2023
22 tasks
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.

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.