From 39e15bbea1edd4ec149f70772fb3371a90e81c46 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Wed, 9 Nov 2022 21:00:48 +0100 Subject: [PATCH] Reduce file string allocations --- src/game/common/system/file.cpp | 13 ++++++++++++- src/game/common/system/file.h | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/game/common/system/file.cpp b/src/game/common/system/file.cpp index 5474c022d..02230491e 100644 --- a/src/game/common/system/file.cpp +++ b/src/game/common/system/file.cpp @@ -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(""); + } // namespace Thyme +File::File() : m_access(0), m_open(false), m_deleteOnClose(false) +{ + // Set_Name(""); + m_name = Thyme::s_defaultFileName; +} + File::~File() { File::Close(); @@ -93,7 +103,8 @@ bool File::Open(const char *filename, int mode) void File::Close() { if (m_open) { - Set_Name(""); + // Set_Name(""); + m_name = Thyme::s_defaultFileName; m_open = false; if (m_deleteOnClose) { diff --git a/src/game/common/system/file.h b/src/game/common/system/file.h index 0614624d7..139d26feb 100644 --- a/src/game/common/system/file.h +++ b/src/game/common/system/file.h @@ -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(""); } + File(); protected: Utf8String m_name;