diff --git a/include/wx/log.h b/include/wx/log.h index 4bc3b587b8..514dc84b6b 100644 --- a/include/wx/log.h +++ b/include/wx/log.h @@ -395,18 +395,13 @@ public: // return the effective log level for this component, falling back to // parent component and to the default global log level if necessary - // - // 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); + static wxLogLevel GetComponentLevel(const wxString& component); // is logging of messages from this component enabled at this level? // // 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); } diff --git a/src/common/log.cpp b/src/common/log.cpp index fe169a6b45..04b910d724 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -603,10 +603,13 @@ void wxLog::SetComponentLevel(const wxString& component, wxLogLevel level) } /* static */ -wxLogLevel wxLog::GetComponentLevel(wxString component) +wxLogLevel wxLog::GetComponentLevel(const wxString& componentOrig) { wxCRIT_SECT_LOCKER(lock, GetLevelsCS()); + // Make a copy before modifying it in the loop. + wxString component = componentOrig; + const wxStringToNumHashMap& componentLevels = GetComponentLevels(); while ( !component.empty() ) {