From 94c9ee4593b17d3cc0397e9552eff26220e24aed Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 22 Aug 2023 20:06:15 +0200 Subject: [PATCH] - got rid of the remaining persistent std::strings in the file system. This also uses the string pool now. --- src/common/filesystem/file_whres.cpp | 8 +++++--- src/common/filesystem/filesystem.cpp | 2 +- src/common/filesystem/resourcefile.cpp | 7 ++++--- src/common/filesystem/resourcefile.h | 5 +++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/common/filesystem/file_whres.cpp b/src/common/filesystem/file_whres.cpp index 8629e6a642..ba07945b3f 100644 --- a/src/common/filesystem/file_whres.cpp +++ b/src/common/filesystem/file_whres.cpp @@ -35,6 +35,7 @@ */ #include "resourcefile.h" +#include "fs_stringpool.h" #include "fs_swap.h" using namespace fs_private; @@ -47,7 +48,7 @@ using namespace fs_private; class FWHResFile : public FUncompressedFile { - std::string basename; + const char* BaseName; public: FWHResFile(const char * filename, FileReader &file, StringPool* sp); bool Open(LumpFilterInfo* filter); @@ -63,7 +64,7 @@ public: FWHResFile::FWHResFile(const char *filename, FileReader &file, StringPool* sp) : FUncompressedFile(filename, file, sp) { - basename = ExtractBaseName(filename, false); + BaseName = stringpool->Strdup(ExtractBaseName(filename, false).c_str()); } //========================================================================== @@ -91,7 +92,8 @@ bool FWHResFile::Open(LumpFilterInfo*) if (length == 0) break; char num[5]; snprintf(num, 5, "/%04d", k); - std::string synthname = basename + num; + std::string synthname = BaseName; + synthname += num; Lumps[i].LumpNameSetup(synthname.c_str(), stringpool); Lumps[i].Owner = this; Lumps[i].Position = offset; diff --git a/src/common/filesystem/filesystem.cpp b/src/common/filesystem/filesystem.cpp index 0589943b7f..60a62697da 100644 --- a/src/common/filesystem/filesystem.cpp +++ b/src/common/filesystem/filesystem.cpp @@ -307,7 +307,7 @@ void FileSystem::AddLump(FResourceLump *lump) int FileSystem::AddExternalFile(const char *filename) { - FResourceLump *lump = new FExternalLump(filename); + FResourceLump *lump = new FExternalLump(filename, -1, stringpool); AddLump(lump); return (int)FileInfo.size() - 1; // later } diff --git a/src/common/filesystem/resourcefile.cpp b/src/common/filesystem/resourcefile.cpp index 17dcbdd257..6e75255913 100644 --- a/src/common/filesystem/resourcefile.cpp +++ b/src/common/filesystem/resourcefile.cpp @@ -692,9 +692,10 @@ FUncompressedFile::FUncompressedFile(const char *filename, FileReader &r, String // //========================================================================== -FExternalLump::FExternalLump(const char *_filename, int filesize) - : Filename(_filename) +FExternalLump::FExternalLump(const char *_filename, int filesize, StringPool* stringpool) { + FileName = stringpool->Strdup(_filename); + if (filesize == -1) { FileReader f; @@ -727,7 +728,7 @@ int FExternalLump::FillCache() Cache = new char[LumpSize]; FileReader f; - if (f.OpenFile(Filename.c_str())) + if (f.OpenFile(FileName)) { auto read = f.Read(Cache, LumpSize); if (read != LumpSize) diff --git a/src/common/filesystem/resourcefile.h b/src/common/filesystem/resourcefile.h index 86e56970f6..4619bbeb0c 100644 --- a/src/common/filesystem/resourcefile.h +++ b/src/common/filesystem/resourcefile.h @@ -218,11 +218,12 @@ protected: }; +// should only be used internally. struct FExternalLump : public FResourceLump { - std::string Filename; + const char* FileName; - FExternalLump(const char *_filename, int filesize = -1); + FExternalLump(const char *_filename, int filesize, StringPool* sp); virtual int FillCache() override; };