From 535eb9a8535220bda4e0a1321e311fe22795f216 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 20 Aug 2023 00:56:56 +0200 Subject: [PATCH] - use std::vector in GetFilesInFolder --- src/common/filesystem/filesystem.cpp | 16 ++++++++-------- src/common/filesystem/filesystem.h | 2 +- src/common/fonts/font.cpp | 15 ++++++++------- src/common/fonts/v_font.cpp | 4 ++-- src/common/fonts/v_font.h | 2 +- src/common/textures/texturemanager.cpp | 2 +- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/common/filesystem/filesystem.cpp b/src/common/filesystem/filesystem.cpp index 237ac4c88..c1f3144b1 100644 --- a/src/common/filesystem/filesystem.cpp +++ b/src/common/filesystem/filesystem.cpp @@ -1241,13 +1241,13 @@ static int folderentrycmp(const void *a, const void *b) // //========================================================================== -unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray &result, bool atomic) const +unsigned FileSystem::GetFilesInFolder(const char *inpath, std::vector &result, bool atomic) const { std::string path = inpath; FixPathSeparator(&path.front()); for (auto& c : path) c = tolower(c); if (path.back() != '/') path += '/'; - result.Clear(); + result.clear(); for (size_t i = 0; i < FileInfo.size(); i++) { if (FileInfo[i].longName.find(path) == 0) @@ -1256,11 +1256,11 @@ unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray &r if ((unsigned)fileSystem.CheckNumForFullName(FileInfo[i].longName.c_str()) == i) { FolderEntry fe{ FileInfo[i].longName.c_str(), (uint32_t)i }; - result.Push(fe); + result.push_back(fe); } } } - if (result.Size()) + if (result.size()) { int maxfile = -1; if (atomic) @@ -1272,14 +1272,14 @@ unsigned FileSystem::GetFilesInFolder(const char *inpath, TArray &r if (thisfile > maxfile) maxfile = thisfile; } // Delete everything from older files. - for (int i = result.Size() - 1; i >= 0; i--) + for (int i = (int)result.size() - 1; i >= 0; i--) { - if (fileSystem.GetFileContainer(result[i].lumpnum) != maxfile) result.Delete(i); + if (fileSystem.GetFileContainer(result[i].lumpnum) != maxfile) result.erase(result.begin() + i); } } - qsort(result.Data(), result.Size(), sizeof(FolderEntry), folderentrycmp); + qsort(result.data(), result.size(), sizeof(FolderEntry), folderentrycmp); } - return result.Size(); + return (unsigned)result.size(); } //========================================================================== diff --git a/src/common/filesystem/filesystem.h b/src/common/filesystem/filesystem.h index cb4695280..6470a20bf 100644 --- a/src/common/filesystem/filesystem.h +++ b/src/common/filesystem/filesystem.h @@ -144,7 +144,7 @@ public: int GetResourceId(int lump) const; // Returns the RFF index number for this lump const char* GetResourceType(int lump) const; bool CheckFileName (int lump, const char *name) const; // [RH] Returns true if the names match - unsigned GetFilesInFolder(const char *path, TArray &result, bool atomic) const; + unsigned GetFilesInFolder(const char *path, std::vector &result, bool atomic) const; int GetNumEntries() const { diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 3876dd7ea..063f31077 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -91,7 +91,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla // Read the font's configuration. // This will not be done for the default fonts, because they are not atomic and the default content does not need it. - TArray folderdata; + std::vector folderdata; if (filetemplate != nullptr) { FStringf path("fonts/%s/", filetemplate); @@ -103,12 +103,13 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla { FStringf infpath("fonts/%s/font.inf", filetemplate); - unsigned index = folderdata.FindEx([=](const FolderEntry &entry) + size_t index; + for(index = 0; index < folderdata.size(); index++) { - return infpath.CompareNoCase(entry.name) == 0; - }); + if (infpath.CompareNoCase(folderdata[i].name) == 0) break; + } - if (index < folderdata.Size()) + if (index < folderdata.size()) { FScanner sc; sc.OpenLumpNum(folderdata[index].lumpnum); @@ -288,7 +289,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla } } } - if (folderdata.Size() > 0) + if (folderdata.size() > 0) { // all valid lumps must be named with a hex number that represents its Unicode character index. for (auto &entry : folderdata) @@ -397,7 +398,7 @@ public: } }; -void FFont::ReadSheetFont(TArray &folderdata, int width, int height, const DVector2 &Scale) +void FFont::ReadSheetFont(std::vector &folderdata, int width, int height, const DVector2 &Scale) { TMap charMap; int minchar = INT_MAX; diff --git a/src/common/fonts/v_font.cpp b/src/common/fonts/v_font.cpp index cb206a4ec..f6e4ef0de 100644 --- a/src/common/fonts/v_font.cpp +++ b/src/common/fonts/v_font.cpp @@ -109,7 +109,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname) int lump = -1; int folderfile = -1; - TArray folderdata; + std::vector folderdata; FStringf path("fonts/%s/", name); // Use a folder-based font only if it comes from a later file than the single lump version. @@ -149,7 +149,7 @@ FFont *V_GetFont(const char *name, const char *fontlumpname) return font; } } - if (folderdata.Size() > 0) + if (folderdata.size() > 0) { font = new FFont(name, nullptr, name, 0, 0, 1, -1); if (translationsLoaded) font->LoadTranslations(); diff --git a/src/common/fonts/v_font.h b/src/common/fonts/v_font.h index 407ee0f5e..9fdab0228 100644 --- a/src/common/fonts/v_font.h +++ b/src/common/fonts/v_font.h @@ -175,7 +175,7 @@ protected: void FixXMoves(); - void ReadSheetFont(TArray &folderdata, int width, int height, const DVector2 &Scale); + void ReadSheetFont(std::vector &folderdata, int width, int height, const DVector2 &Scale); EFontType Type = EFontType::Unknown; FName AltFontName = NAME_None; diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 444b3b4eb..969a5f201 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -1108,7 +1108,7 @@ void FTextureManager::SortTexturesByType(int start, int end) void FTextureManager::AddLocalizedVariants() { - TArray content; + std::vector content; fileSystem.GetFilesInFolder("localized/textures/", content, false); for (auto &entry : content) {