@@ -10,28 +10,34 @@ internal static class FileTreeHelper
1010 /// <summary>
1111 /// Constructs the full name of a file by combining the path and the name.
1212 /// </summary>
13- /// <param name="buffer ">A buffer used for constructing the full name.
13+ /// <param name="chars ">A buffer used for constructing the full name.
1414 /// It should be obtained from an array pool and will be resized if necessary.</param>
1515 /// <param name="path">The path of the file.</param>
1616 /// <param name="name">The name of the file.</param>
1717 /// <returns>
1818 /// A <see cref="ReadOnlySpan{T}"/> representing the full name of the file.
1919 /// </returns>
20- public static ReadOnlySpan < char > GetFullName ( ref char [ ] buffer , string path , string name )
20+ public static ReadOnlySpan < char > GetFullName ( ref char [ ] chars , string path , string name )
2121 {
22- var length = path . Length + name . Length + 1 ;
23- if ( buffer . Length < length )
22+ var array = chars ;
23+ var count = path . Length + name . Length + 1 ;
24+
25+ if ( array . Length < count )
2426 {
25- ArrayPool < char > . Shared . Return ( buffer ) ;
26- buffer = ArrayPool < char > . Shared . Rent ( length ) ;
27+ ArrayPool < char > . Shared . Return ( array ) ;
28+ array = ArrayPool < char > . Shared . Rent ( count ) ;
29+ chars = array ;
30+
31+ // Force null check to assist JIT
32+ _ = array . Length ;
2733 }
2834
29- var fullName = buffer . AsSpan ( 0 , length ) ;
35+ var fullName = array . AsSpan ( ) ;
3036
3137 path . TryCopyTo ( fullName ) ;
3238 fullName [ path . Length ] = '/' ;
3339 name . TryCopyTo ( fullName . Slice ( path . Length + 1 ) ) ;
3440
35- return fullName ;
41+ return fullName . Slice ( 0 , count ) ;
3642 }
3743}
0 commit comments