-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add Path.Join() methods. #16561
Add Path.Join() methods. #16561
Changes from all commits
48d52d8
b71b0e9
6e07cb4
a6fc5c9
2bba548
3cb5dec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -10,8 +10,12 @@ internal static partial class PathInternal | |||
/// <summary> | ||||
/// Returns true if the path ends in a directory separator. | ||||
/// </summary> | ||||
internal static bool EndsInDirectorySeparator(string path) => | ||||
!string.IsNullOrEmpty(path) && IsDirectorySeparator(path[path.Length - 1]); | ||||
internal static bool EndsInDirectorySeparator(ReadOnlySpan<char> path) => path.Length > 0 && IsDirectorySeparator(path[path.Length - 1]); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We seem to only call these methods when path.Length is greater than 0 anyway. Can the length check be a Debug.Assert instead? Same with StartsWithDirectorySeparator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is true now, but I expect that to change, particularly as I expect to include this file in a few CoreFX libraries. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We seem to have EndsInDirectorySeparator in already:
But not in Path.Unix.cs (and we don't have StartsWithDirectorySeparator) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, missed that. I'll get this one. I have a fair amount of cleanup to do- I intend to do so when I include the Path sources directly in System.Runtime.Extensions again. |
||||
|
||||
/// <summary> | ||||
/// Returns true if the path starts in a directory separator. | ||||
/// </summary> | ||||
internal static bool StartsWithDirectorySeparator(ReadOnlySpan<char> path) => path.Length > 0 && IsDirectorySeparator(path[0]); | ||||
|
||||
/// <summary> | ||||
/// Get the common path length from the start of the string. | ||||
|
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.
I think this can be optimized similar to the 2 path overload (probably even bigger impact), but I don't think it needs to block this PR. Feel free to file an issue/optimize outside this change.
I would suggest, however, that we do the following instead of calling the methods that do the length checks:
IsDirectorySeparator(path1[path1.Length - 1])
IsDirectorySeparator(path2[0])