This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed
src/Common/src/CoreLib/System/IO Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -119,13 +119,15 @@ internal static string RemoveRelativeSegments(string path, int skip = 0)
119119 Debug . Assert ( skip >= 0 ) ;
120120 bool flippedSeparator = false ;
121121
122+ Span < char > initialBuffer = stackalloc char [ 260 /* PathInternal.MaxShortPath */ ] ;
123+ ValueStringBuilder sb = new ValueStringBuilder ( initialBuffer ) ;
124+
122125 // Remove "//", "/./", and "/../" from the path by copying each character to the output,
123126 // except the ones we're removing, such that the builder contains the normalized path
124127 // at the end.
125- StringBuilder sb = StringBuilderCache . Acquire ( path . Length ) ;
126128 if ( skip > 0 )
127129 {
128- sb . Append ( path , 0 , skip ) ;
130+ sb . Append ( path . AsSpan ( ) . Slice ( 0 , skip ) ) ;
129131 }
130132
131133 for ( int i = skip ; i < path . Length ; i ++ )
@@ -186,16 +188,14 @@ internal static string RemoveRelativeSegments(string path, int skip = 0)
186188 sb . Append ( c ) ;
187189 }
188190
189- if ( flippedSeparator || sb . Length != path . Length )
190- {
191- return StringBuilderCache . GetStringAndRelease ( sb ) ;
192- }
193- else
191+ // If we haven't changed the source path, return the original
192+ if ( ! flippedSeparator && sb . Length == path . Length )
194193 {
195- // We haven't changed the source path, return the original
196- StringBuilderCache . Release ( sb ) ;
194+ sb . Dispose ( ) ;
197195 return path ;
198196 }
197+
198+ return sb . ToString ( ) ;
199199 }
200200 }
201201}
You can’t perform that action at this time.
0 commit comments