Stop passing wxString by value to wxLog::GetComponentLevel()
This function is almost exclusively called from IsLevelEnabled() which doesn't get inlined (at least by MSVS) when wxString is passed by value to it, and so had to be updated to take a const reference instead, which means that a copy is always going to be made anyhow, so don't try to be smart and avoid it -- it doesn't work anyhow and just results in unusual code, requiring explanatory comments (not needed any longer) and upsetting static code analyzers. No real changes. See https://github.com/wxWidgets/wxWidgets/pull/1387
This commit is contained in:
@@ -395,18 +395,13 @@ public:
|
|||||||
|
|
||||||
// return the effective log level for this component, falling back to
|
// return the effective log level for this component, falling back to
|
||||||
// parent component and to the default global log level if necessary
|
// parent component and to the default global log level if necessary
|
||||||
//
|
static wxLogLevel GetComponentLevel(const wxString& component);
|
||||||
// NB: component argument is passed by value and not const reference in an
|
|
||||||
// attempt to encourage compiler to avoid an extra copy: as we modify
|
|
||||||
// the component internally, we'd create one anyhow and like this it
|
|
||||||
// can be avoided if the string is a temporary anyhow
|
|
||||||
static wxLogLevel GetComponentLevel(wxString component);
|
|
||||||
|
|
||||||
|
|
||||||
// is logging of messages from this component enabled at this level?
|
// is logging of messages from this component enabled at this level?
|
||||||
//
|
//
|
||||||
// usually always called with wxLOG_COMPONENT as second argument
|
// usually always called with wxLOG_COMPONENT as second argument
|
||||||
static bool IsLevelEnabled(wxLogLevel level, wxString component)
|
static bool IsLevelEnabled(wxLogLevel level, const wxString& component)
|
||||||
{
|
{
|
||||||
return IsEnabled() && level <= GetComponentLevel(component);
|
return IsEnabled() && level <= GetComponentLevel(component);
|
||||||
}
|
}
|
||||||
|
@@ -603,10 +603,13 @@ void wxLog::SetComponentLevel(const wxString& component, wxLogLevel level)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
wxLogLevel wxLog::GetComponentLevel(wxString component)
|
wxLogLevel wxLog::GetComponentLevel(const wxString& componentOrig)
|
||||||
{
|
{
|
||||||
wxCRIT_SECT_LOCKER(lock, GetLevelsCS());
|
wxCRIT_SECT_LOCKER(lock, GetLevelsCS());
|
||||||
|
|
||||||
|
// Make a copy before modifying it in the loop.
|
||||||
|
wxString component = componentOrig;
|
||||||
|
|
||||||
const wxStringToNumHashMap& componentLevels = GetComponentLevels();
|
const wxStringToNumHashMap& componentLevels = GetComponentLevels();
|
||||||
while ( !component.empty() )
|
while ( !component.empty() )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user