Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce file string allocations #788

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading