@@ -196,18 +196,18 @@ protected override void CopyFileImpl(UPath srcPath, UPath destPath, bool overwri
196
196
197
197
if ( srcEntry == null )
198
198
{
199
- if ( ! DirectoryExistsImpl ( srcPath . GetDirectory ( ) ) )
199
+ if ( ! DirectoryExistsImpl ( srcPath . GetDirectoryAsSpan ( ) ) )
200
200
{
201
201
throw new DirectoryNotFoundException ( srcPath . GetDirectory ( ) . FullName ) ;
202
202
}
203
203
204
204
throw FileSystemExceptionHelper . NewFileNotFoundException ( srcPath ) ;
205
205
}
206
206
207
- var parentDirectory = destPath . GetDirectory ( ) ;
207
+ var parentDirectory = destPath . GetDirectoryAsSpan ( ) ;
208
208
if ( ! DirectoryExistsImpl ( parentDirectory ) )
209
209
{
210
- throw FileSystemExceptionHelper . NewDirectoryNotFoundException ( parentDirectory ) ;
210
+ throw FileSystemExceptionHelper . NewDirectoryNotFoundException ( parentDirectory . ToString ( ) ) ;
211
211
}
212
212
213
213
if ( DirectoryExistsImpl ( destPath ) )
@@ -261,12 +261,12 @@ protected override void CreateDirectoryImpl(UPath path)
261
261
throw FileSystemExceptionHelper . NewDestinationDirectoryExistException ( path ) ;
262
262
}
263
263
264
- var parentPath = new UPath ( GetParent ( path . FullName ) ) ;
265
- if ( parentPath != "" )
264
+ var parentPath = GetParent ( path . AsSpan ( ) ) ;
265
+ if ( ! parentPath . IsEmpty )
266
266
{
267
267
if ( ! DirectoryExistsImpl ( parentPath ) )
268
268
{
269
- CreateDirectoryImpl ( parentPath ) ;
269
+ CreateDirectoryImpl ( parentPath . ToString ( ) ) ;
270
270
}
271
271
}
272
272
@@ -405,7 +405,12 @@ protected override void DeleteFileImpl(UPath path)
405
405
/// <inheritdoc />
406
406
protected override bool DirectoryExistsImpl ( UPath path )
407
407
{
408
- if ( path . FullName is "/" or "\\ " or "" )
408
+ return DirectoryExistsImpl ( path . FullName . AsSpan ( ) ) ;
409
+ }
410
+
411
+ private bool DirectoryExistsImpl ( ReadOnlySpan < char > path )
412
+ {
413
+ if ( path is "/" or "\\ " or "" )
409
414
{
410
415
return true ;
411
416
}
@@ -414,7 +419,11 @@ protected override bool DirectoryExistsImpl(UPath path)
414
419
415
420
try
416
421
{
417
- return _entries . TryGetValue ( path , out var entry ) && entry . IsDirectory ;
422
+ #if HAS_ALTERNATEEQUALITYCOMPARER
423
+ return _entries . GetAlternateLookup < ReadOnlySpan < char > > ( ) . TryGetValue ( path , out var entry ) && entry . IsDirectory ;
424
+ #else
425
+ return _entries . TryGetValue ( path . ToString ( ) , out var entry ) && entry . IsDirectory ;
426
+ #endif
418
427
}
419
428
finally
420
429
{
@@ -651,7 +660,7 @@ protected override void MoveFileImpl(UPath srcPath, UPath destPath)
651
660
{
652
661
var srcEntry = GetEntry ( srcPath ) ?? throw FileSystemExceptionHelper . NewFileNotFoundException ( srcPath ) ;
653
662
654
- if ( ! DirectoryExistsImpl ( destPath . GetDirectory ( ) ) )
663
+ if ( ! DirectoryExistsImpl ( destPath . GetDirectoryAsSpan ( ) ) )
655
664
{
656
665
throw FileSystemExceptionHelper . NewDirectoryNotFoundException ( destPath . GetDirectory ( ) ) ;
657
666
}
@@ -706,7 +715,7 @@ protected override Stream OpenFileImpl(UPath path, FileMode mode, FileAccess acc
706
715
}
707
716
else
708
717
{
709
- if ( ! DirectoryExistsImpl ( path . GetDirectory ( ) ) )
718
+ if ( ! DirectoryExistsImpl ( path . GetDirectoryAsSpan ( ) ) )
710
719
{
711
720
throw FileSystemExceptionHelper . NewDirectoryNotFoundException ( path . GetDirectory ( ) ) ;
712
721
}
@@ -911,18 +920,18 @@ private ZipArchiveEntry CreateEntry(UPath path, bool isDirectory = false)
911
920
912
921
private static readonly char [ ] s_slashChars = { '/' , '\\ ' } ;
913
922
914
- private static string GetName ( ZipArchiveEntry entry )
923
+ private static ReadOnlySpan < char > GetName ( ZipArchiveEntry entry )
915
924
{
916
925
var name = entry . FullName . TrimEnd ( s_slashChars ) ;
917
926
var index = name . LastIndexOfAny ( s_slashChars ) ;
918
- return name . Substring ( index + 1 ) ;
927
+ return index == - 1 ? name . AsSpan ( ) : name . AsSpan ( index + 1 ) ;
919
928
}
920
929
921
- private static string GetParent ( string path )
930
+ private static ReadOnlySpan < char > GetParent ( ReadOnlySpan < char > path )
922
931
{
923
932
path = path . TrimEnd ( s_slashChars ) ;
924
933
var lastIndex = path . LastIndexOfAny ( s_slashChars ) ;
925
- return lastIndex == - 1 ? "" : path . Substring ( 0 , lastIndex ) ;
934
+ return lastIndex == - 1 ? ReadOnlySpan < char > . Empty : path . Slice ( 0 , lastIndex ) ;
926
935
}
927
936
928
937
private FileSystemEventDispatcher < FileSystemWatcher > ? TryGetDispatcher ( )
0 commit comments