From 1f9dd057977475d846a0063e72c334a370012c40 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 8 Jul 2019 10:00:36 +0200 Subject: [PATCH] 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 --- include/wx/log.h | 9 ++------- src/common/log.cpp | 5 ++++- 2 files changed, 6 insertions(+), 8 deletions(-) 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() ) {