[Libreoffice-commits] core.git: include/sal sal/osl sal/util

Arnold Dumas arnold at dumas.at
Fri Feb 3 10:55:28 UTC 2017


 include/sal/log.hxx |    5 +
 sal/osl/all/log.cxx |  162 ++++++++++++++++++++++++++--------------------------
 sal/util/sal.map    |    1 
 3 files changed, 86 insertions(+), 82 deletions(-)

New commits:
commit b3a11c8f4f307bbbb597c9c6e7e61ee93e794873
Author: Arnold Dumas <arnold at dumas.at>
Date:   Thu Feb 2 20:50:44 2017 +0100

    tdf#91872: Make SAL_INFO and friends more efficient
    
    Change-Id: I8a5b1665660b0679439f07d3924bb90cb4c4075c
    Reviewed-on: https://gerrit.libreoffice.org/33848
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/sal/log.hxx b/include/sal/log.hxx
index 4438ec5..ea070dd 100644
--- a/include/sal/log.hxx
+++ b/include/sal/log.hxx
@@ -34,6 +34,9 @@ extern "C" SAL_DLLPUBLIC void SAL_CALL sal_detail_log_backtrace(
     enum sal_detail_LogLevel level, char const * area, char const * where,
     char const * message, int maxNoStackFramesToDisplay);
 
+extern "C" SAL_DLLPUBLIC int SAL_CALL sal_detail_log_report(
+    enum sal_detail_LogLevel level, char const * area);
+
 namespace sal { namespace detail {
 
 inline void SAL_CALL log(
@@ -116,7 +119,7 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) {
 
 #define SAL_DETAIL_LOG_STREAM(condition, level, area, where, stream) \
     do { \
-        if (condition) { \
+        if ((condition) && sal_detail_log_report(level, area)) { \
             if (sizeof ::sal::detail::getResult( \
                     ::sal::detail::StreamStart() << stream) == 1) \
             { \
diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 7245a51..5e4497f 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -190,84 +190,6 @@ bool isDebug(sal_detail_LogLevel level) {
     return level == SAL_DETAIL_LOG_LEVEL_DEBUG;
 }
 
-bool report(sal_detail_LogLevel level, char const * area) {
-    if (isDebug(level))
-        return true;
-    assert(area != nullptr);
-    char const * env = getEnvironmentVariable();
-    if (env == nullptr) {
-        env = "+WARN";
-    }
-    std::size_t areaLen = std::strlen(area);
-    enum Sense { POSITIVE = 0, NEGATIVE = 1 };
-    std::size_t senseLen[2] = { 0, 1 };
-        // initial senseLen[POSITIVE] < senseLen[NEGATIVE], so that if there are
-        // no matching switches at all, the result will be negative (and
-        // initializing with 1 is safe as the length of a valid switch, even
-        // without the "+"/"-" prefix, will always be > 1)
-    bool seenWarn = false;
-    for (char const * p = env;;) {
-        Sense sense;
-        switch (*p++) {
-        case '\0':
-            if (level == SAL_DETAIL_LOG_LEVEL_WARN && !seenWarn)
-                return report(SAL_DETAIL_LOG_LEVEL_INFO, area);
-            return senseLen[POSITIVE] >= senseLen[NEGATIVE];
-                // if a specific item is both positive and negative
-                // (senseLen[POSITIVE] == senseLen[NEGATIVE]), default to
-                // positive
-        case '+':
-            sense = POSITIVE;
-            break;
-        case '-':
-            sense = NEGATIVE;
-            break;
-        default:
-            return true; // upon an illegal SAL_LOG value, enable everything
-        }
-        char const * p1 = p;
-        while (*p1 != '.' && *p1 != '+' && *p1 != '-' && *p1 != '\0') {
-            ++p1;
-        }
-        bool match;
-        if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("INFO"))) {
-            match = level == SAL_DETAIL_LOG_LEVEL_INFO;
-        } else if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("WARN")))
-        {
-            match = level == SAL_DETAIL_LOG_LEVEL_WARN;
-            seenWarn = true;
-        } else if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("TIMESTAMP")) ||
-                   equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("RELATIVETIMER")))
-        {
-            // handled later
-            match = false;
-        } else {
-            return true;
-                // upon an illegal SAL_LOG value, everything is considered
-                // positive
-        }
-        char const * p2 = p1;
-        while (*p2 != '+' && *p2 != '-' && *p2 != '\0') {
-            ++p2;
-        }
-        if (match) {
-            if (*p1 == '.') {
-                ++p1;
-                std::size_t n = p2 - p1;
-                if ((n == areaLen && equalStrings(p1, n, area, areaLen))
-                    || (n < areaLen && area[n] == '.'
-                        && equalStrings(p1, n, area, n)))
-                {
-                    senseLen[sense] = p2 - p;
-                }
-            } else {
-                senseLen[sense] = p1 - p;
-            }
-        }
-        p = p2;
-    }
-}
-
 void log(
     sal_detail_LogLevel level, char const * area, char const * where,
     char const * message)
@@ -367,7 +289,7 @@ void sal_detail_log(
     sal_detail_LogLevel level, char const * area, char const * where,
     char const * message)
 {
-    if (report(level, area)) {
+    if (sal_detail_log_report(level, area)) {
         log(level, area, where, message);
     }
 }
@@ -376,7 +298,7 @@ void sal_detail_log_backtrace(
     sal_detail_LogLevel level, char const * area, char const * where,
     char const * message, int maxNoStackFramesToDisplay)
 {
-    if (report(level, area)) {
+    if (sal_detail_log_report(level, area)) {
         log_backtrace(level, area, where, message, maxNoStackFramesToDisplay);
     }
 }
@@ -385,7 +307,7 @@ void sal_detail_logFormat(
     sal_detail_LogLevel level, char const * area, char const * where,
     char const * format, ...)
 {
-    if (report(level, area)) {
+    if (sal_detail_log_report(level, area)) {
         std::va_list args;
         va_start(args, format);
         char buf[1024];
@@ -401,4 +323,82 @@ void sal_detail_logFormat(
     }
 }
 
+int sal_detail_log_report(enum sal_detail_LogLevel level, char const * area) {
+    if (isDebug(level))
+        return true;
+    assert(area != nullptr);
+    char const * env = getEnvironmentVariable();
+    if (env == nullptr) {
+        env = "+WARN";
+    }
+    std::size_t areaLen = std::strlen(area);
+    enum Sense { POSITIVE = 0, NEGATIVE = 1 };
+    std::size_t senseLen[2] = { 0, 1 };
+        // initial senseLen[POSITIVE] < senseLen[NEGATIVE], so that if there are
+        // no matching switches at all, the result will be negative (and
+        // initializing with 1 is safe as the length of a valid switch, even
+        // without the "+"/"-" prefix, will always be > 1)
+    bool seenWarn = false;
+    for (char const * p = env;;) {
+        Sense sense;
+        switch (*p++) {
+        case '\0':
+            if (level == SAL_DETAIL_LOG_LEVEL_WARN && !seenWarn)
+                return sal_detail_log_report(SAL_DETAIL_LOG_LEVEL_INFO, area);
+            return senseLen[POSITIVE] >= senseLen[NEGATIVE];
+                // if a specific item is both positive and negative
+                // (senseLen[POSITIVE] == senseLen[NEGATIVE]), default to
+                // positive
+        case '+':
+            sense = POSITIVE;
+            break;
+        case '-':
+            sense = NEGATIVE;
+            break;
+        default:
+            return true; // upon an illegal SAL_LOG value, enable everything
+        }
+        char const * p1 = p;
+        while (*p1 != '.' && *p1 != '+' && *p1 != '-' && *p1 != '\0') {
+            ++p1;
+        }
+        bool match;
+        if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("INFO"))) {
+            match = level == SAL_DETAIL_LOG_LEVEL_INFO;
+        } else if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("WARN")))
+        {
+            match = level == SAL_DETAIL_LOG_LEVEL_WARN;
+            seenWarn = true;
+        } else if (equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("TIMESTAMP")) ||
+                   equalStrings(p, p1 - p, RTL_CONSTASCII_STRINGPARAM("RELATIVETIMER")))
+        {
+            // handled later
+            match = false;
+        } else {
+            return true;
+                // upon an illegal SAL_LOG value, everything is considered
+                // positive
+        }
+        char const * p2 = p1;
+        while (*p2 != '+' && *p2 != '-' && *p2 != '\0') {
+            ++p2;
+        }
+        if (match) {
+            if (*p1 == '.') {
+                ++p1;
+                std::size_t n = p2 - p1;
+                if ((n == areaLen && equalStrings(p1, n, area, areaLen))
+                    || (n < areaLen && area[n] == '.'
+                        && equalStrings(p1, n, area, n)))
+                {
+                    senseLen[sense] = p2 - p;
+                }
+            } else {
+                senseLen[sense] = p1 - p;
+            }
+        }
+        p = p2;
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/util/sal.map b/sal/util/sal.map
index 96ea9d1..b99d524 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -731,6 +731,7 @@ PRIVATE_1.2 { # LibreOffice 3.5
 PRIVATE_1.3 { # LibreOffice 5.4
     global:
         sal_detail_log_backtrace;
+        sal_detail_log_report;
 } PRIVATE_1.2;
 
 PRIVATE_textenc.1 { # LibreOffice 3.6


More information about the Libreoffice-commits mailing list