Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 50901c6

Browse files
committed
Merge pull request #2656 from justinvp/zipfile_isdirempty
ZipFile: Reduce allocations in IsDirEmpty
2 parents 6b5a8ae + d58c770 commit 50901c6

File tree

1 file changed

+3
-4
lines changed
  • src/System.IO.Compression.ZipFile/src/System/IO/Compression

1 file changed

+3
-4
lines changed

src/System.IO.Compression.ZipFile/src/System/IO/Compression/ZipFile.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.Collections.Generic;
45
using System.Diagnostics;
56
using System.Text;
67

@@ -569,10 +570,8 @@ private static string EntryFromPath(string entry, int offset, int length)
569570

570571
private static Boolean IsDirEmpty(DirectoryInfo possiblyEmptyDir)
571572
{
572-
foreach (FileSystemInfo fi in possiblyEmptyDir.EnumerateFileSystemInfos("*", SearchOption.AllDirectories))
573-
return false;
574-
575-
return true;
573+
using (IEnumerator<String> enumerator = Directory.EnumerateFileSystemEntries(possiblyEmptyDir.FullName).GetEnumerator())
574+
return !enumerator.MoveNext();
576575
}
577576
} // class ZipFile
578577
} // namespace

0 commit comments

Comments
 (0)