Skip to content

Commit

Permalink
simplified the directory reader a little bit
Browse files Browse the repository at this point in the history
* we do not need to make a second allocation for the systemFilePath
* as systemFilePath is never null, there is no need to check for that case.
* moved systemFilePath into a separate array to save memory on other file types.
  • Loading branch information
coelckers committed Dec 24, 2023
1 parent f8dcc33 commit baa9251
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/common/filesystem/include/resourcefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ struct FResourceEntry
uint16_t Flags;
uint16_t Method;
int16_t Namespace;
const char* SystemFilePath;
};

void SetMainThread();
Expand Down
9 changes: 5 additions & 4 deletions src/common/filesystem/source/file_directory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class FDirectory : public FResourceFile
{
const bool nosubdir;
const char* mBasePath;
const char** SystemFilePath;


int AddDirectory(const char* dirpath, LumpFilterInfo* filter, FileSystemMessageFunc Printf);

Expand Down Expand Up @@ -102,6 +104,7 @@ int FDirectory::AddDirectory(const char *dirpath, LumpFilterInfo* filter, FileSy
{
mBasePath = nullptr;
AllocateEntries((int)list.size());
SystemFilePath = (const char**)stringpool->Alloc(list.size() * sizeof(const char*));
for(auto& entry : list)
{
if (mBasePath == nullptr)
Expand Down Expand Up @@ -131,7 +134,7 @@ int FDirectory::AddDirectory(const char *dirpath, LumpFilterInfo* filter, FileSy
}
// for internal access we use the normalized form of the relative path.
Entries[count].FileName = NormalizeFileName(entry.FilePathRel.c_str());
Entries[count].SystemFilePath = stringpool->Strdup(Entries[count].FileName);
SystemFilePath[count] = Entries[count].FileName;
Entries[count].CompressedSize = Entries[count].Length = entry.Length;
Entries[count].Flags = RESFF_FULLPATH;
Entries[count].ResourceID = -1;
Expand Down Expand Up @@ -170,9 +173,7 @@ FileReader FDirectory::GetEntryReader(uint32_t entry, int readertype, int)
if (entry < NumLumps)
{
std::string fn = mBasePath;
fn += Entries[entry].SystemFilePath ?
Entries[entry].SystemFilePath :
Entries[entry].FileName;
fn += SystemFilePath[entry];
fr.OpenFile(fn.c_str());
if (readertype == READER_CACHED)
{
Expand Down

0 comments on commit baa9251

Please sign in to comment.