FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use span-based overloads by iSazonov · Pull Request #11884 · PowerShell/PowerShell · GitHub

Use span-based overloads - #11884

Merged
Ilya (iSazonov) merged 3 commits into
PowerShell:masterfrom
iSazonov:cleanup-use-span-overloads
Mar 18, 2020
Merged

Use span-based overloads#11884
Ilya (iSazonov) merged 3 commits into
PowerShell:masterfrom
iSazonov:cleanup-use-span-overloads

Conversation

Ilya (iSazonov) commented Feb 19, 2020
edited
Loading

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

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Ilya (iSazonov) Feb 20, 2020
edited
Loading

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Rain Sallow (/u/ta11ow) (@vexx32) No, only string -> ReadOnlySpan

Rain Sallow (/u/ta11ow) (vexx32) Feb 21, 2020
edited
Loading

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I missing some context here

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

Copy link
Copy Markdown
Collaborator Author

Added new commit.

Ilya (iSazonov) force-pushed the cleanup-use-span-overloads branch from 2627a51 to 372c510 Compare February 20, 2020 09:16
Ilya (iSazonov) force-pushed the cleanup-use-span-overloads branch from 372c510 to 3e3fad1 Compare March 9, 2020 17:31

Steve Lee (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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

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

Copy link
Copy Markdown

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

Handy links:

Ilya (iSazonov) mentioned this pull request Oct 29, 2020
14 tasks
Ilya (iSazonov) mentioned this pull request Jan 3, 2023
22 tasks
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL