prevent CLogWindow::UpdateLog from constantly burning through timer objects, because it was allocating memory a lot and making it hard to debug some things. I think this should be faster even in release builds, but any speedup is probably too tiny to measure.

This commit is contained in:
nitsuja 2011-12-30 20:51:17 -08:00
parent f0d7b8122f
commit 0d9e87da18
2 changed files with 42 additions and 36 deletions

View File

@ -39,7 +39,7 @@ CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style, const wxString& name) const wxSize& size, long style, const wxString& name)
: wxPanel(parent, id, pos, size, style, name) : wxPanel(parent, id, pos, size, style, name)
, x(0), y(0), winpos(0) , x(0), y(0), winpos(0)
, Parent(parent) , m_LogAccess(true) , Parent(parent), m_ignoreLogTimer(false), m_LogAccess(true)
, m_Log(NULL), m_cmdline(NULL), m_FontChoice(NULL) , m_Log(NULL), m_cmdline(NULL), m_FontChoice(NULL)
, m_SJISConv(*(wxCSConv*)wxConvCurrent) , m_SJISConv(*(wxCSConv*)wxConvCurrent)
{ {
@ -279,6 +279,7 @@ void CLogWindow::OnWrapLineCheck(wxCommandEvent& event)
void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event)) void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event))
{ {
if (!m_LogAccess) return; if (!m_LogAccess) return;
if (m_ignoreLogTimer) return;
UpdateLog(); UpdateLog();
// Scroll to the last line // Scroll to the last line
@ -294,8 +295,12 @@ void CLogWindow::UpdateLog()
if (!m_LogAccess) return; if (!m_LogAccess) return;
if (!m_Log) return; if (!m_Log) return;
m_LogTimer->Stop(); // m_LogTimer->Stop();
// instead of stopping the timer, let's simply ignore its calls during UpdateLog,
// because repeatedly stopping and starting a timer churns memory (and potentially leaks it).
m_ignoreLogTimer = true;
if (!msgQueue.empty())
{ {
std::lock_guard<std::mutex> lk(m_LogSection); std::lock_guard<std::mutex> lk(m_LogSection);
int msgQueueSize = (int)msgQueue.size(); int msgQueueSize = (int)msgQueue.size();
@ -303,7 +308,6 @@ void CLogWindow::UpdateLog()
{ {
switch (msgQueue.front().first) switch (msgQueue.front().first)
{ {
case ERROR_LEVEL: case ERROR_LEVEL:
m_Log->SetDefaultStyle(wxTextAttr(*wxRED)); m_Log->SetDefaultStyle(wxTextAttr(*wxRED));
break; break;
@ -339,7 +343,8 @@ void CLogWindow::UpdateLog()
} }
} // unlock log } // unlock log
m_LogTimer->Start(UPDATETIME); // m_LogTimer->Start(UPDATETIME);
m_ignoreLogTimer = false;
} }
void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text) void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text)

View File

@ -62,6 +62,7 @@ private:
wxFont DefaultFont, MonoSpaceFont; wxFont DefaultFont, MonoSpaceFont;
std::vector<wxFont> LogFont; std::vector<wxFont> LogFont;
wxTimer *m_LogTimer; wxTimer *m_LogTimer;
bool m_ignoreLogTimer;
LogManager *m_LogManager; LogManager *m_LogManager;
std::queue<std::pair<u8, wxString> > msgQueue; std::queue<std::pair<u8, wxString> > msgQueue;
bool m_writeFile, m_writeConsole, m_writeWindow, m_LogAccess; bool m_writeFile, m_writeConsole, m_writeWindow, m_LogAccess;