Skip to content

Commit

Permalink
PR #402 Only convert entry.Name once when accessing updateIndex
Browse files Browse the repository at this point in the history
* don't convert entry.Name twice when accessing updateIndex

* Update src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs

Accepted suggestion

Co-Authored-By: nils måsén <nils@piksel.se>

* Update src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs

Co-Authored-By: nils måsén <nils@piksel.se>

* Update src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs

Co-Authored-By: nils måsén <nils@piksel.se>

* Update src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs

Co-Authored-By: nils måsén <nils@piksel.se>

Co-authored-by: nils måsén <nils@piksel.se>
  • Loading branch information
AqlaSolutions and piksel authored Aug 7, 2020
1 parent bf4372a commit 24f948a
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ private void AddUpdate(ZipUpdate update)
{
contentsEdited_ = true;

int index = FindExistingUpdate(update.Entry.Name);
int index = FindExistingUpdate(update.Entry.Name, isEntryName: true);

if (index >= 0)
{
Expand Down Expand Up @@ -2555,13 +2555,9 @@ private void CopyEntryDataDirect(ZipUpdate update, Stream stream, bool updateCrc
private int FindExistingUpdate(ZipEntry entry)
{
int result = -1;
string convertedName = entry.IsDirectory
? GetTransformedDirectoryName(entry.Name)
: GetTransformedFileName(entry.Name);

if (updateIndex_.ContainsKey(convertedName))
if (updateIndex_.ContainsKey(entry.Name))
{
result = (int)updateIndex_[convertedName];
result = (int)updateIndex_[entry.Name];
}
/*
// This is slow like the coming of the next ice age but takes less storage and may be useful
Expand All @@ -2579,11 +2575,11 @@ private int FindExistingUpdate(ZipEntry entry)
return result;
}

private int FindExistingUpdate(string fileName)
private int FindExistingUpdate(string fileName, bool isEntryName = false)
{
int result = -1;

string convertedName = GetTransformedFileName(fileName);
string convertedName = !isEntryName ? GetTransformedFileName(fileName) : fileName;

if (updateIndex_.ContainsKey(convertedName))
{
Expand Down

0 comments on commit 24f948a

Please sign in to comment.