diff options
author | Stephen Toub <stoub@microsoft.com> | 2022-06-16 18:14:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-16 18:14:27 +0300 |
commit | 9ab00ef5c8904f28fba9b01b4fefd4ad672567fb (patch) | |
tree | b99ec4b287fe97b6da9c337fdb54baf8642c4f5e | |
parent | f25caab2211a411f3682124a89266da6cdaad1de (diff) |
Use LastIndexOf in ZipArchiveEntry.GetFileName_Unix (#70701)
There's not particularly good reason to open-code the loop here.
-rw-r--r-- | src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs index 0e1fb422095..3a672848eeb 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs @@ -1104,11 +1104,10 @@ namespace System.IO.Compression /// </summary> private static string GetFileName_Unix(string path) { - int length = path.Length; - for (int i = length; --i >= 0;) - if (path[i] == '/') - return path.Substring(i + 1); - return path; + int i = path.LastIndexOf('/'); + return i >= 0 ? + path.Substring(i + 1) : + path; } private sealed class DirectToArchiveWriterStream : Stream |