-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Avoid creation of temporary strings where possible #11380
base: main
Are you sure you want to change the base?
Conversation
string extension = Path.GetExtension(path); | ||
|
||
if (string.Equals(extension, ".dll", StringComparison.OrdinalIgnoreCase)) | ||
if (!string.IsNullOrEmpty(path) && path.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path.HasExtension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That means "does this path have an extension", not "does this path have the specified extension", sadly.
string extension = Path.GetExtension(path); | ||
|
||
if (string.Equals(extension, ".dll", StringComparison.OrdinalIgnoreCase)) | ||
if (!string.IsNullOrEmpty(path) && path.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That means "does this path have an extension", not "does this path have the specified extension", sadly.
@@ -299,7 +299,11 @@ public bool IsTraversal | |||
{ | |||
if (!_isTraversalProject.HasValue) | |||
{ | |||
if (String.Equals(Path.GetFileName(ProjectFullPath), "dirs.proj", StringComparison.OrdinalIgnoreCase)) | |||
#if NET471_OR_GREATER | |||
if (MemoryExtensions.Equals(Microsoft.IO.Path.GetFileName(ProjectFullPath.AsSpan()), "dirs.proj".AsSpan(), StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you doing this explicitly here to be conservative/localized (totally legit!) or because there's a reason not to shift to Microsoft.IO.Redist elsewhere in this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There can be subtle differences in behavior between NetFX System.IO.Path and Microsoft.IO.Path, so this was meant to be a surgical update to minimize churn. In other repositories, we've seen measurable improvement fully switching over to Microsoft.IO, so this should be considered as well.
One thing to note: Since Microsoft.IO is a snapshot of improvements backported for NetFX, we want to use System.IO in .NET 5+. That way we'll continue to benefit from future improvements.
Fixes #
Context
Changes Made
Testing
Notes