Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 3ac69e8

Browse files
authored
Change RootDirectory properties to span (#27134)
Exposing string restricts the ability to change internals without introducing unnecessary allocations.
1 parent bda2ef6 commit 3ac69e8

File tree

5 files changed

+13
-32
lines changed

5 files changed

+13
-32
lines changed

src/System.IO.FileSystem/ref/System.IO.FileSystem.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ namespace System.IO.Enumeration
251251
public ref struct FileSystemEntry
252252
{
253253
public ReadOnlySpan<char> Directory { get { throw null; } }
254-
public string RootDirectory { get { throw null; } }
255-
public string OriginalRootDirectory { get { throw null; } }
254+
public ReadOnlySpan<char> RootDirectory { get { throw null; } }
255+
public ReadOnlySpan<char> OriginalRootDirectory { get { throw null; } }
256256
public ReadOnlySpan<char> FileName { get { throw null; } }
257257
public FileAttributes Attributes { get { throw null; } }
258258
public long Length { get { throw null; } }

src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEntry.Unix.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ internal static FileAttributes Initialize(
2121
ref FileSystemEntry entry,
2222
Interop.Sys.DirectoryEntry directoryEntry,
2323
ReadOnlySpan<char> directory,
24-
string rootDirectory,
25-
string originalRootDirectory,
24+
ReadOnlySpan<char> rootDirectory,
25+
ReadOnlySpan<char> originalRootDirectory,
2626
Span<char> pathBuffer)
2727
{
2828
entry._directoryEntry = directoryEntry;
@@ -62,7 +62,6 @@ internal static FileAttributes Initialize(
6262
return attributes;
6363
}
6464

65-
6665
private ReadOnlySpan<char> FullPath
6766
{
6867
get
@@ -106,12 +105,12 @@ public ReadOnlySpan<char> FileName
106105
/// <summary>
107106
/// The full path of the root directory used for the enumeration.
108107
/// </summary>
109-
public string RootDirectory { get; private set; }
108+
public ReadOnlySpan<char> RootDirectory { get; private set; }
110109

111110
/// <summary>
112111
/// The root directory for the enumeration as specified in the constructor.
113112
/// </summary>
114-
public string OriginalRootDirectory { get; private set; }
113+
public ReadOnlySpan<char> OriginalRootDirectory { get; private set; }
115114

116115
public FileAttributes Attributes => _status.GetAttributes(FullPath, FileName);
117116
public long Length => _status.GetLength(FullPath);

src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEntry.Windows.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ internal static void Initialize(
1313
ref FileSystemEntry entry,
1414
Interop.NtDll.FILE_FULL_DIR_INFORMATION* info,
1515
ReadOnlySpan<char> directory,
16-
string rootDirectory,
17-
string originalRootDirectory)
16+
ReadOnlySpan<char> rootDirectory,
17+
ReadOnlySpan<char> originalRootDirectory)
1818
{
1919
entry._info = info;
2020
entry.Directory = directory;
@@ -32,12 +32,12 @@ internal static void Initialize(
3232
/// <summary>
3333
/// The full path of the root directory used for the enumeration.
3434
/// </summary>
35-
public string RootDirectory { get; private set; }
35+
public ReadOnlySpan<char> RootDirectory { get; private set; }
3636

3737
/// <summary>
3838
/// The root directory for the enumeration as specified in the constructor.
3939
/// </summary>
40-
public string OriginalRootDirectory { get; private set; }
40+
public ReadOnlySpan<char> OriginalRootDirectory { get; private set; }
4141

4242
/// <summary>
4343
/// The file name for this entry.

src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using System.Buffers;
66
using System.Collections.Generic;
7-
using System.Runtime.CompilerServices;
87
using System.Runtime.ConstrainedExecution;
98
using System.Runtime.InteropServices;
109
using System.Threading;

src/System.IO.FileSystem/src/System/IO/PathHelpers.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,6 @@ internal static ReadOnlySpan<char> TrimEndingDirectorySeparator(ReadOnlySpan<cha
4949
path.Slice(0, path.Length - 1) :
5050
path;
5151

52-
/// <summary>
53-
/// Combines two paths. Does no validation of paths, only concatenates the paths
54-
/// and places a directory separator between them if needed.
55-
/// </summary>
56-
internal static string CombineNoChecks(string first, ReadOnlySpan<char> second)
57-
{
58-
if (string.IsNullOrEmpty(first))
59-
return second.Length == 0
60-
? string.Empty
61-
: new string(second);
62-
63-
if (second.Length == 0)
64-
return first;
65-
66-
return CombineNoChecksInternal(first.AsReadOnlySpan(), second);
67-
}
68-
6952
/// <summary>
7053
/// Combines two paths. Does no validation of paths, only concatenates the paths
7154
/// and places a directory separator between them if needed.
@@ -87,9 +70,9 @@ internal static string CombineNoChecks(ReadOnlySpan<char> first, ReadOnlySpan<ch
8770
/// Combines three paths. Does no validation of paths, only concatenates the paths
8871
/// and places a directory separator between them if needed.
8972
/// </summary>
90-
internal static string CombineNoChecks(string first, ReadOnlySpan<char> second, ReadOnlySpan<char> third)
73+
internal static string CombineNoChecks(ReadOnlySpan<char> first, ReadOnlySpan<char> second, ReadOnlySpan<char> third)
9174
{
92-
if (string.IsNullOrEmpty(first))
75+
if (first.Length == 0)
9376
return CombineNoChecks(second, third);
9477

9578
if (second.Length == 0)
@@ -98,7 +81,7 @@ internal static string CombineNoChecks(string first, ReadOnlySpan<char> second,
9881
if (third.Length == 0)
9982
return CombineNoChecks(first, second);
10083

101-
return CombineNoChecksInternal(first.AsReadOnlySpan(), second, third);
84+
return CombineNoChecksInternal(first, second, third);
10285
}
10386

10487
[MethodImpl(MethodImplOptions.AggressiveInlining)]

0 commit comments

Comments
 (0)