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

Simplify NtProcessInfoHelper.GetProcessShortName #71136

Merged
merged 1 commit into from
Jun 22, 2022

Conversation

stephentoub
Copy link
Member

The previous code was iterating character by character through the name, looking for the last occurrence of a slash and the last occurrence of a period. For the slash, we can just LasIndexOfAny. For the period, it was only doing this in order to trim off ".exe" if a period was found and the text at that point was ".exe"... so we can just compare the end with ".exe".

The previous code was iterating character by character through the name, looking for the last occurrence of a slash and the last occurrence of a period.  For the slash, we can just LasIndexOfAny.  For the period, it was only doing this in order to trim off ".exe" if a period was found and the text at that point was ".exe"... so we can just compare the end with ".exe".
@ghost
Copy link

ghost commented Jun 22, 2022

Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.

Issue Details

The previous code was iterating character by character through the name, looking for the last occurrence of a slash and the last occurrence of a period. For the slash, we can just LasIndexOfAny. For the period, it was only doing this in order to trim off ".exe" if a period was found and the text at that point was ".exe"... so we can just compare the end with ".exe".

Author: stephentoub
Assignees: stephentoub
Labels:

area-System.Diagnostics.Process

Milestone: -

{
slash++; // point to character next to slash
name = name.Slice(0, name.Length - 4);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name = name.Slice(0, name.Length - 4);
name = name[..^4];

@stephentoub stephentoub merged commit 9d3f060 into dotnet:main Jun 22, 2022
@stephentoub stephentoub deleted the simplifyprocessname branch June 22, 2022 20:57
@ghost ghost locked as resolved and limited conversation to collaborators Jul 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants