Skip to content

Commit

Permalink
Reduce file string allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
xezon authored and tomsons26 committed Feb 5, 2024
1 parent 13c2fc0 commit 39e15bb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/game/common/system/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,18 @@ bool Decode_Buffered_File_Mode(int mode, int &buffer_size)
}
return false;
}

// Optimization to reduce string allocations.
const Utf8String s_defaultFileName("<no file>");

} // namespace Thyme

File::File() : m_access(0), m_open(false), m_deleteOnClose(false)
{
// Set_Name("<no file>");
m_name = Thyme::s_defaultFileName;
}

File::~File()
{
File::Close();
Expand Down Expand Up @@ -93,7 +103,8 @@ bool File::Open(const char *filename, int mode)
void File::Close()
{
if (m_open) {
Set_Name("<no file>");
// Set_Name("<no file>");
m_name = Thyme::s_defaultFileName;
m_open = false;

if (m_deleteOnClose) {
Expand Down
2 changes: 1 addition & 1 deletion src/game/common/system/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class File : public MemoryPoolObject
void Delete_On_Close() { m_deleteOnClose = true; }

protected:
File() : m_access(0), m_open(false), m_deleteOnClose(false) { Set_Name("<no file>"); }
File();

protected:
Utf8String m_name;
Expand Down

0 comments on commit 39e15bb

Please sign in to comment.