From 0b6d21e3d50fe4d832d56e5cf1607146b04cf632 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 20 Oct 2015 13:22:48 +0200 Subject: [PATCH] Logger: don't call qFormatLog when unessesary That's a lot of string operations that can be avoided if the log window is not shown --- src/libsync/logger.cpp | 24 +++++++++++++++++++++++- src/libsync/logger.h | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/libsync/logger.cpp b/src/libsync/logger.cpp index c3ac1f1f2..d4767dced 100644 --- a/src/libsync/logger.cpp +++ b/src/libsync/logger.cpp @@ -17,6 +17,7 @@ #include #include #include +#include namespace OCC { @@ -40,7 +41,10 @@ static void mirallLogCatcher(QtMsgType, const QMessageLogContext &ctx, const QSt } #else static void mirallLogCatcher(QtMsgType type, const QMessageLogContext &ctx, const QString &message) { - Logger::instance()->doLog( qFormatLogMessage(type, ctx, message) ) ; + auto logger = Logger::instance(); + if (!logger->isNoop()) { + logger->doLog( qFormatLogMessage(type, ctx, message) ) ; + } } #endif @@ -105,6 +109,24 @@ void Logger::log(Log log) doLog(msg); } +/** + * Returns true if doLog does nothing and need not to be called + */ +bool Logger::isNoop() const +{ +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) + return false; +#else + static auto signal = QMetaMethod::fromSignal(&Logger::newLog); + if (isSignalConnected(signal)) { + return false; + } + QMutexLocker lock(const_cast(&_mutex)); + return !_logstream; +#endif +} + + void Logger::doLog(const QString& msg) { { diff --git a/src/libsync/logger.h b/src/libsync/logger.h index ada8f26be..d73d32b69 100644 --- a/src/libsync/logger.h +++ b/src/libsync/logger.h @@ -46,6 +46,7 @@ class OWNCLOUDSYNC_EXPORT Logger : public QObject Q_OBJECT public: + bool isNoop() const; void log(Log log); void doLog(const QString &log); -- 2.30.2