Don't call time() from wxLogRecordInfo ctor
This is a tiny optimization (or maybe not so tiny on platforms other than Linux where time() might not as fast as just reading a memory location), but mostly is done to work around faketime bug[*] which prevented it from being used for testing programs using wxWidgets, such as our own unit tests because time() was called from wxLogTrace() in wxCSConv::DoCreate() called when creating global conversion objects during the library initialization. Arguably, it might be better to avoid calling wxLogTrace() during the initialization, but this can't be done as simply and this change might have a small performance benefit too. [*] https://github.com/wolfcw/libfaketime/issues/132
This commit is contained in:
@@ -158,7 +158,11 @@ public:
|
|||||||
line = line_;
|
line = line_;
|
||||||
component = component_;
|
component = component_;
|
||||||
|
|
||||||
timestamp = time(NULL);
|
// don't initialize the timestamp yet, we might not need it at all if
|
||||||
|
// the message doesn't end up being logged and otherwise we'll fill it
|
||||||
|
// just before logging it, which won't change it by much and definitely
|
||||||
|
// less than a second resolution of the timestamp
|
||||||
|
timestamp = 0;
|
||||||
|
|
||||||
#if wxUSE_THREADS
|
#if wxUSE_THREADS
|
||||||
threadId = wxThread::GetCurrentId();
|
threadId = wxThread::GetCurrentId();
|
||||||
@@ -1162,6 +1166,11 @@ private:
|
|||||||
|
|
||||||
void DoCallOnLog(wxLogLevel level, const wxString& format, va_list argptr)
|
void DoCallOnLog(wxLogLevel level, const wxString& format, va_list argptr)
|
||||||
{
|
{
|
||||||
|
// As explained in wxLogRecordInfo ctor, we don't initialize its
|
||||||
|
// timestamp to avoid calling time() unnecessary, but now that we are
|
||||||
|
// about to log the message, we do need to do it.
|
||||||
|
m_info.timestamp = time(NULL);
|
||||||
|
|
||||||
wxLog::OnLog(level, wxString::FormatV(format, argptr), m_info);
|
wxLog::OnLog(level, wxString::FormatV(format, argptr), m_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user