diff options
author | Jeremie Laval <jeremie.laval@gmail.com> | 2012-11-29 19:14:44 +0400 |
---|---|---|
committer | Jeremie Laval <jeremie.laval@gmail.com> | 2012-11-29 19:21:05 +0400 |
commit | 1f6a2697fcd19f81a939d1b44adcf9ed79621a70 (patch) | |
tree | 1ec9d62527794adfd4622cc7f33f1d1031310d4f | |
parent | 43f36c19ba49214349eb745d6a5559a294e7b7bf (diff) |
[monkeydoc] Use a map to quickly access zip archive content.
-rw-r--r-- | mcs/tools/monkeydoc/Monkeydoc/storage/ZipStorage.cs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/mcs/tools/monkeydoc/Monkeydoc/storage/ZipStorage.cs b/mcs/tools/monkeydoc/Monkeydoc/storage/ZipStorage.cs index b04ee39556a..81ed1c5bd66 100644 --- a/mcs/tools/monkeydoc/Monkeydoc/storage/ZipStorage.cs +++ b/mcs/tools/monkeydoc/Monkeydoc/storage/ZipStorage.cs @@ -15,6 +15,8 @@ namespace MonkeyDoc.Storage int code; ZipOutputStream zipOutput; ZipFile zipFile; + // SharpZipLib use linear search to map name to index, correct that a bit + Dictionary<string, int> entries = new Dictionary<string, int> (); public ZipStorage (string zipFileName) { @@ -78,7 +80,10 @@ namespace MonkeyDoc.Storage public Stream Retrieve (string id) { EnsureInput (); - ZipEntry entry = zipFile.GetEntry (id); + int index; + ZipEntry entry; + if (!entries.TryGetValue (id, out index) || (entry = zipFile[index]) == null) + entry = zipFile.GetEntry (id); if (entry != null) return zipFile.GetInputStream (entry); else @@ -107,6 +112,7 @@ namespace MonkeyDoc.Storage if (zipFile != null) return; zipFile = new ZipFile (zipFileName); + entries = Enumerable.Range (0, zipFile.Size).ToDictionary (i => zipFile[i].Name, i => i); } public void Dispose () |