Skip to content

Conversation

@iSazonov
Copy link
Collaborator

@iSazonov iSazonov commented Feb 19, 2020

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
Copy link
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?

Copy link
Collaborator Author

@iSazonov iSazonov Feb 20, 2020

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
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
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

Copy link
Collaborator

@vexx32 vexx32 Feb 21, 2020

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
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
Collaborator Author

Added new commit.

@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
Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
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
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
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
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
Copy link

ghost commented Mar 26, 2020

🎉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