Take C string in wxLogger::MaybeStore() to simplify

We don't need to take wxString here, when we only ever call this
function ourselves with ASCII strings only.

This should result in slightly shorter generated code too, as the
conversion from C string to wxString now happens only in a single place
inside MaybeStore() instead of being done in all places calling
wxLogSysError() or wxLogStatus().
This commit is contained in:
Vadim Zeitlin 2024-01-30 18:47:06 +01:00
parent 10f235b43c
commit fb8d7b7de0

View file

@ -921,12 +921,15 @@ public:
// indicates that we may have an extra first argument preceding the format
// string and that if we do have it, we should store it in m_info using the
// given key (while by default 0 value will be used)
wxLogger& MaybeStore(const wxString& key, wxUIntPtr value = 0)
wxLogger& MaybeStore(const char* key, wxUIntPtr value = 0)
{
wxASSERT_MSG( m_optKey.empty(), "can only have one optional value" );
m_optKey = key;
m_info.StoreValue(key, value);
// We only use keys defined in this file and we can be sure they
// contain ASCII characters only.
m_optKey = wxString::FromAscii(key);
m_info.StoreValue(m_optKey, value);
return *this;
}
@ -1208,7 +1211,7 @@ WXDLLIMPEXP_BASE wxString wxSysErrorMsgStr(unsigned long nErrCode = 0);
// and it will have changed already by then (in fact it even changes when
// wxString::Format() is called because of vsnprintf() inside it so it can
// change even much sooner)
#define wxLOG_KEY_SYS_ERROR_CODE wxASCII_STR("wx.sys_error")
#define wxLOG_KEY_SYS_ERROR_CODE "wx.sys_error"
#define wxLogSysError \
wxDO_LOG_IF_ENABLED_WITH_FUNC(Error, MaybeStore(wxLOG_KEY_SYS_ERROR_CODE, \
@ -1224,7 +1227,7 @@ WXDLLIMPEXP_BASE wxString wxSysErrorMsgStr(unsigned long nErrCode = 0);
#if wxUSE_GUI
// wxLogStatus() is similar to wxLogSysError() as it allows to optionally
// specify the frame to which the message should go
#define wxLOG_KEY_FRAME wxASCII_STR("wx.frame")
#define wxLOG_KEY_FRAME "wx.frame"
#define wxLogStatus \
wxDO_LOG_IF_ENABLED_WITH_FUNC(Status, MaybeStore(wxLOG_KEY_FRAME).Log)