Skip to content

Commit

Permalink
Use LastIndexOf in ZipArchiveEntry.GetFileName_Unix (dotnet#70701)
Browse files Browse the repository at this point in the history
There's not particularly good reason to open-code the loop here.
  • Loading branch information
stephentoub authored Jun 16, 2022
1 parent f25caab commit 9ab00ef
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1104,11 +1104,10 @@ private static string GetFileName_Windows(string path)
/// </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
Expand Down

0 comments on commit 9ab00ef

Please sign in to comment.