- replaced a few temporary allocations with TArray and added a few convenience loader functions for this.

Amazingly with today's optimizers this creates code which is just as good as doing it all manually with the added benefit of being safer.
This commit is contained in:
Christoph Oelckers 2018-11-10 11:56:18 +01:00
commit 3448749de6
10 changed files with 60 additions and 39 deletions

View file

@ -1281,6 +1281,30 @@ void FWadCollection::ReadLump (int lump, void *dest)
}
}
//==========================================================================
//
// W_ReadLump
//
// Loads the lump into a TArray and returns it.
//
//==========================================================================
TArray<uint8_t> FWadCollection::ReadLumpIntoArray(int lump, int pad)
{
auto lumpr = OpenLumpReader(lump);
auto size = lumpr.GetLength();
TArray<uint8_t> data(size + pad);
auto numread = lumpr.Read(data.Data(), size);
if (numread != size)
{
I_Error("W_ReadLump: only read %ld of %ld on lump %i\n",
numread, size, lump);
}
if (pad > 0) memset(&data[size], 0, pad);
return data;
}
//==========================================================================
//
// ReadLump - variant 2