From 24f948af9289d004c925848a466db1450d26f7d6 Mon Sep 17 00:00:00 2001 From: Vladyslav Taranov Date: Fri, 7 Aug 2020 17:52:00 +0300 Subject: [PATCH] PR #402 Only convert entry.Name once when accessing updateIndex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * Update src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs Co-Authored-By: nils måsén * Update src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs Co-Authored-By: nils måsén * Update src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs Co-Authored-By: nils måsén Co-authored-by: nils måsén --- src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs index c12a53df1..056785e16 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs @@ -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) { @@ -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 @@ -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)) {