Skip to content

Commit

Permalink
Replace wildcards with something that is faster overall and for debug…
Browse files Browse the repository at this point in the history
… builds in particular
  • Loading branch information
dpjudas committed Feb 1, 2025
1 parent 87bda3d commit b8078fd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1,843 deletions.
3 changes: 2 additions & 1 deletion src/common/filesystem/include/resourcefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct LumpFilterInfo
std::vector<std::string> reservedFolders;
std::vector<std::string> requiredPrefixes;
std::vector<std::string> embeddings;
std::vector<std::string> blockednames; // File names that will never be accepted (e.g. dehacked.exe for Doom)
std::vector<std::string> blockedextensions; // File extensions that will never be accepted (e.g. .exe and .bat)
std::vector<std::string> blockedfolders; // File folders that will never be accepted (e.g. __macosx)
std::function<bool(const char*, const char*)> filenamecheck; // for scanning directories, this allows to eliminate unwanted content.
std::function<void()> postprocessFunc;
};
Expand Down
55 changes: 47 additions & 8 deletions src/common/filesystem/source/resourcefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#include "unicode.h"
#include "fs_findfile.h"
#include "fs_decompress.h"
#include "wildcards.hpp"
#include <string_view>
#include <algorithm>

namespace FileSys {
Expand Down Expand Up @@ -344,6 +344,46 @@ void FResourceFile::GenerateHash()
}
}

static bool IsBlockedExt(LumpFilterInfo* filter, const std::string_view& name)
{
size_t extpos = name.find_last_of('.');
if (extpos != std::string::npos)
{
std::string_view ext = name.substr(extpos);
for (const auto& blockedext : filter->blockedextensions)
{
if (ext == blockedext)
return true;
}
}
return false;
}

static bool IsBlockedFolder(LumpFilterInfo* filter, const std::string_view& name)
{
size_t start = 0;
while (true)
{
size_t end = std::min(name.find_first_of("/\\", start), name.size());
std::string_view folder = name.substr(start, end - start);

if (folder.empty())
break;

for (const auto& blockedfolder : filter->blockedfolders)
{
if (folder == blockedfolder)
return true;
}

if (end == name.size())
break;

start = end + 1;
}
return false;
}

//==========================================================================
//
// FResourceFile :: PostProcessArchive
Expand All @@ -365,14 +405,13 @@ void FResourceFile::PostProcessArchive(LumpFilterInfo *filter)
{
for (uint32_t i = 0; i < NumLumps; i++)
{
std::string name = Entries[i].FileName;
for (auto& pattern : filter->blockednames)
// Note: this used wildcards::match before. That was super slow in debug builds in particular.
// Do not change it back to wildcards, please.

std::string_view name = Entries[i].FileName;
if (IsBlockedExt(filter, name) || IsBlockedFolder(filter, name))
{
if (wildcards::match(name, pattern))
{
Entries[i].FileName = "";
continue;
}
Entries[i].FileName = "";
}
}
}
Expand Down
Loading

0 comments on commit b8078fd

Please sign in to comment.