From c07aeb7498d1524563b47da71b0cc1a4593c6875 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 2 Nov 2018 09:51:44 +0100 Subject: [PATCH] - use a single TArray to allocate the memory for the lump manager's hash lists. --- src/w_wad.cpp | 48 +++++++----------------------------------------- src/w_wad.h | 4 ++-- 2 files changed, 9 insertions(+), 43 deletions(-) diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 41b57811d..9c474ceb8 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -101,10 +101,6 @@ void uppercopy (char *to, const char *from) } FWadCollection::FWadCollection () -: FirstLumpIndex(NULL), NextLumpIndex(NULL), - FirstLumpIndex_FullName(NULL), NextLumpIndex_FullName(NULL), - FirstLumpIndex_NoExt(NULL), NextLumpIndex_NoExt(NULL), - NumLumps(0) { } @@ -115,37 +111,6 @@ FWadCollection::~FWadCollection () void FWadCollection::DeleteAll () { - if (FirstLumpIndex != NULL) - { - delete[] FirstLumpIndex; - FirstLumpIndex = NULL; - } - if (NextLumpIndex != NULL) - { - delete[] NextLumpIndex; - NextLumpIndex = NULL; - } - if (FirstLumpIndex_FullName != NULL) - { - delete[] FirstLumpIndex_FullName; - FirstLumpIndex_FullName = NULL; - } - if (NextLumpIndex_FullName != NULL) - { - delete[] NextLumpIndex_FullName; - NextLumpIndex_FullName = NULL; - } - if (FirstLumpIndex_NoExt != NULL) - { - delete[] FirstLumpIndex_NoExt; - FirstLumpIndex_NoExt = NULL; - } - if (NextLumpIndex_NoExt != NULL) - { - delete[] NextLumpIndex_NoExt; - NextLumpIndex_NoExt = NULL; - } - LumpInfo.Clear(); NumLumps = 0; @@ -193,12 +158,13 @@ void FWadCollection::InitMultipleFiles (TArray &filenames) FixMacHexen(); // [RH] Set up hash table - FirstLumpIndex = new uint32_t[NumLumps]; - NextLumpIndex = new uint32_t[NumLumps]; - FirstLumpIndex_FullName = new uint32_t[NumLumps]; - NextLumpIndex_FullName = new uint32_t[NumLumps]; - FirstLumpIndex_NoExt = new uint32_t[NumLumps]; - NextLumpIndex_NoExt = new uint32_t[NumLumps]; + Hashes.Resize(6 * NumLumps); + FirstLumpIndex = &Hashes[0]; + NextLumpIndex = &Hashes[NumLumps]; + FirstLumpIndex_FullName = &Hashes[NumLumps*2]; + NextLumpIndex_FullName = &Hashes[NumLumps*3]; + FirstLumpIndex_NoExt = &Hashes[NumLumps*4]; + NextLumpIndex_NoExt = &Hashes[NumLumps*5]; InitHashChains (); LumpInfo.ShrinkToFit(); Files.ShrinkToFit(); diff --git a/src/w_wad.h b/src/w_wad.h index 30d73d33e..dca4bd8fe 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -188,6 +188,7 @@ protected: TArray Files; TArray LumpInfo; + TArray Hashes; // one allocation for all hash lists. uint32_t *FirstLumpIndex; // [RH] Hashing stuff moved out of lumpinfo structure uint32_t *NextLumpIndex; @@ -197,12 +198,11 @@ protected: uint32_t *FirstLumpIndex_NoExt; // The same information for fully qualified paths from .zips uint32_t *NextLumpIndex_NoExt; - uint32_t NumLumps; // Not necessarily the same as LumpInfo.Size() + uint32_t NumLumps = 0; // Not necessarily the same as LumpInfo.Size() uint32_t NumWads; int IwadIndex; - void SkinHack (int baselump); void InitHashChains (); // [RH] Set up the lumpinfo hashing private: