Skip to content

Commit f1358d0

Browse files
authored
Use LastIndexOfAny in GetFileName_Windows (#71032)
1 parent cb32ed3 commit f1358d0

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,14 +1096,10 @@ private void ThrowIfInvalidArchive()
10961096
/// </summary>
10971097
private static string GetFileName_Windows(string path)
10981098
{
1099-
int length = path.Length;
1100-
for (int i = length; --i >= 0;)
1101-
{
1102-
char ch = path[i];
1103-
if (ch == '\\' || ch == '/' || ch == ':')
1104-
return path.Substring(i + 1);
1105-
}
1106-
return path;
1099+
int i = path.AsSpan().LastIndexOfAny('\\', '/', ':');
1100+
return i >= 0 ?
1101+
path.Substring(i + 1) :
1102+
path;
11071103
}
11081104

11091105
/// <summary>

0 commit comments

Comments
 (0)