DirTrees and unpacked archives shouldn't demand a count of entries for init.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 21 Jul 2017 13:54:42 -0400
changeset 1494 4e2c7ce9bf11
parent 1493 66357f286930
child 1495 2ac61188ad60
DirTrees and unpacked archives shouldn't demand a count of entries for init.
src/archiver_7z.c
src/archiver_grp.c
src/archiver_hog.c
src/archiver_mvl.c
src/archiver_qpak.c
src/archiver_slb.c
src/archiver_unpacked.c
src/archiver_wad.c
src/archiver_zip.c
src/physfs.c
src/physfs_internal.h
--- a/src/archiver_7z.c	Thu Jul 20 17:00:21 2017 -0400
+++ b/src/archiver_7z.c	Fri Jul 21 13:54:42 2017 -0400
@@ -183,11 +183,11 @@
 
 static int szipLoadEntries(SZIPinfo *info)
 {
-    const PHYSFS_uint32 count = info->db.NumFiles;
     int retval = 0;
 
-    if (__PHYSFS_DirTreeInit(&info->tree, count, sizeof (SZIPentry)))
+    if (__PHYSFS_DirTreeInit(&info->tree, sizeof (SZIPentry)))
     {
+        const PHYSFS_uint32 count = info->db.NumFiles;
         PHYSFS_uint32 i;
         for (i = 0; i < count; i++)
             BAIL_IF_ERRPASS(!szipLoadEntry(info, i), 0);
--- a/src/archiver_grp.c	Thu Jul 20 17:00:21 2017 -0400
+++ b/src/archiver_grp.c	Fri Jul 21 13:54:42 2017 -0400
@@ -73,7 +73,7 @@
     BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, &count, sizeof(count)), NULL);
     count = PHYSFS_swapULE32(count);
 
-    unpkarc = UNPK_openArchive(io, count);
+    unpkarc = UNPK_openArchive(io);
     BAIL_IF_ERRPASS(!unpkarc, NULL);
 
     if (!grpLoadEntries(io, count, unpkarc))
--- a/src/archiver_hog.c	Thu Jul 20 17:00:21 2017 -0400
+++ b/src/archiver_hog.c	Fri Jul 21 13:54:42 2017 -0400
@@ -72,7 +72,7 @@
     BAIL_IF_ERRPASS(!__PHYSFS_readAll(io, buf, 3), NULL);
     BAIL_IF(memcmp(buf, "DHF", 3) != 0, PHYSFS_ERR_UNSUPPORTED, NULL);
 
-    unpkarc = UNPK_openArchive(io, count);
+    unpkarc = UNPK_openArchive(io);
     BAIL_IF_ERRPASS(!unpkarc, NULL);
 
     if (!hogLoadEntries(io, unpkarc))
--- a/src/archiver_mvl.c	Thu Jul 20 17:00:21 2017 -0400
+++ b/src/archiver_mvl.c	Fri Jul 21 13:54:42 2017 -0400
@@ -67,7 +67,7 @@
 
     count = PHYSFS_swapULE32(count);
 
-    unpkarc = UNPK_openArchive(io, count);
+    unpkarc = UNPK_openArchive(io);
     BAIL_IF_ERRPASS(!unpkarc, NULL);
 
     if (!mvlLoadEntries(io, count, unpkarc))
--- a/src/archiver_qpak.c	Thu Jul 20 17:00:21 2017 -0400
+++ b/src/archiver_qpak.c	Fri Jul 21 13:54:42 2017 -0400
@@ -83,7 +83,7 @@
 
     BAIL_IF_ERRPASS(!io->seek(io, pos), NULL);
 
-    unpkarc = UNPK_openArchive(io, count);
+    unpkarc = UNPK_openArchive(io);
     BAIL_IF_ERRPASS(!unpkarc, NULL);
 
     if (!qpakLoadEntries(io, count, unpkarc))
--- a/src/archiver_slb.c	Thu Jul 20 17:00:21 2017 -0400
+++ b/src/archiver_slb.c	Fri Jul 21 13:54:42 2017 -0400
@@ -93,7 +93,7 @@
     /* seek to the table of contents */
     BAIL_IF_ERRPASS(!io->seek(io, tocPos), NULL);
 
-    unpkarc = UNPK_openArchive(io, count);
+    unpkarc = UNPK_openArchive(io);
     BAIL_IF_ERRPASS(!unpkarc, NULL);
 
     if (!slbLoadEntries(io, count, unpkarc))
--- a/src/archiver_unpacked.c	Thu Jul 20 17:00:21 2017 -0400
+++ b/src/archiver_unpacked.c	Fri Jul 21 13:54:42 2017 -0400
@@ -271,12 +271,12 @@
 } /* UNPK_addEntry */
 
 
-void *UNPK_openArchive(PHYSFS_Io *io, const PHYSFS_uint64 entry_count)
+void *UNPK_openArchive(PHYSFS_Io *io)
 {
     UNPKinfo *info = (UNPKinfo *) allocator.Malloc(sizeof (UNPKinfo));
     BAIL_IF(!info, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
 
-    if (!__PHYSFS_DirTreeInit(&info->tree, entry_count, sizeof (UNPKentry)))
+    if (!__PHYSFS_DirTreeInit(&info->tree, sizeof (UNPKentry)))
     {
         allocator.Free(info);
         return NULL;
--- a/src/archiver_wad.c	Thu Jul 20 17:00:21 2017 -0400
+++ b/src/archiver_wad.c	Fri Jul 21 13:54:42 2017 -0400
@@ -92,7 +92,7 @@
 
     BAIL_IF_ERRPASS(!io->seek(io, directoryOffset), 0);
 
-    unpkarc = UNPK_openArchive(io, count);
+    unpkarc = UNPK_openArchive(io);
     BAIL_IF_ERRPASS(!unpkarc, NULL);
 
     if (!wadLoadEntries(io, count, unpkarc))
--- a/src/archiver_zip.c	Thu Jul 20 17:00:21 2017 -0400
+++ b/src/archiver_zip.c	Fri Jul 21 13:54:42 2017 -0400
@@ -1472,7 +1472,7 @@
 
     if (!zip_parse_end_of_central_dir(info, &dstart, &cdir_ofs, &count))
         goto ZIP_openarchive_failed;
-    else if (!__PHYSFS_DirTreeInit(&info->tree, count, sizeof (ZIPentry)))
+    else if (!__PHYSFS_DirTreeInit(&info->tree, sizeof (ZIPentry)))
         goto ZIP_openarchive_failed;
 
     root = (ZIPentry *) info->tree.root;
--- a/src/physfs.c	Thu Jul 20 17:00:21 2017 -0400
+++ b/src/physfs.c	Fri Jul 21 13:54:42 2017 -0400
@@ -3008,9 +3008,7 @@
 } /* setDefaultAllocator */
 
 
-int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt,
-                        const PHYSFS_uint64 entry_count,
-                        const size_t entrylen)
+int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen)
 {
     static char rootpath[2] = { '/', '\0' };
     size_t alloclen;
@@ -3024,7 +3022,7 @@
     memset(dt->root, '\0', entrylen);
     dt->root->name = rootpath;
     dt->root->isdir = 1;
-    dt->hashBuckets = (size_t) (entry_count / 5);
+    dt->hashBuckets = 64;
     if (!dt->hashBuckets)
         dt->hashBuckets = 1;
     dt->entrylen = entrylen;
--- a/src/physfs_internal.h	Thu Jul 20 17:00:21 2017 -0400
+++ b/src/physfs_internal.h	Fri Jul 21 13:54:42 2017 -0400
@@ -343,7 +343,7 @@
 /* These are shared between some archivers. */
 
 void UNPK_closeArchive(void *opaque);
-void *UNPK_openArchive(PHYSFS_Io *io, const PHYSFS_uint64 entry_count);
+void *UNPK_openArchive(PHYSFS_Io *io);
 void *UNPK_addEntry(void *opaque, char *name, const int isdir,
                     const PHYSFS_uint64 pos, const PHYSFS_uint64 len);
 PHYSFS_Io *UNPK_openRead(void *opaque, const char *name);
@@ -377,9 +377,7 @@
 } __PHYSFS_DirTree;
 
 
-int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt,
-                         const PHYSFS_uint64 entry_count,
-                         const size_t entrylen);
+int __PHYSFS_DirTreeInit(__PHYSFS_DirTree *dt, const size_t entrylen);
 void *__PHYSFS_DirTreeAdd(__PHYSFS_DirTree *dt, char *name, const int isdir);
 void *__PHYSFS_DirTreeFind(__PHYSFS_DirTree *dt, const char *path);
 void __PHYSFS_DirTreeEnumerateFiles(void *opaque, const char *dname,