[Pkg-owncloud-commits] [owncloud-client] 109/484: Logger: don't call qFormatLog when unessesary

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Dec 16 00:37:23 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 0b6d21e3d50fe4d832d56e5cf1607146b04cf632
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Tue Oct 20 13:22:48 2015 +0200

    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 c3ac1f1..d4767dc 100644
--- a/src/libsync/logger.cpp
+++ b/src/libsync/logger.cpp
@@ -17,6 +17,7 @@
 #include <QDir>
 #include <QStringList>
 #include <QThread>
+#include <qmetaobject.h>
 
 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<QMutex *>(&_mutex));
+    return !_logstream;
+#endif
+}
+
+
 void Logger::doLog(const QString& msg)
 {
     {
diff --git a/src/libsync/logger.h b/src/libsync/logger.h
index ada8f26..d73d32b 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);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list