[Libreoffice] Assertions and Logging

Norbert Thiebaud nthiebaud at gmail.com
Wed Nov 23 08:36:22 PST 2011


On Wed, Nov 23, 2011 at 10:12 AM, Stephan Bergmann <sbergman at redhat.com> wrote:
>>
>> If you use a string as a trace-selector you will never get something
>> with performance good-enough for release code.
>> you need a numeric level and a numeric module/feature selector.
>>
>> You need a system so that when the trace are not wanted a trace-point
>> cost a couple of integer testing at worse. you can't take a call, you
>> cant' have to construct arguments for the call,
>> you certainly can't have c++ object instantiation/clone/copy etc...
>
> numbers, please  :)

Seriously ? you need 'numbers' to be convinced that

b == 10

is more performant than (excerpt, not taking into account a couple of
epilogue/prologue among other things...)

    for (char const * p = env;;) {
        Sense sense;
        switch (*p++) {
        case '\0':
            return senseLen[POSITIVE] >= senseLen[NEGATIVE];
                // if a specific item is both postiive 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;
        } 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;
    }

at the very least: restrict the 'area' variable (the one that limit
base on module/feature) in the use-call to be something that could be
part of a variable/constant name
and use the #foo preprocesor to keep it string for now.

#define log(level, area, xxx...)  _log(level, #area, xxx...)

that way at least we will be able to use a numeric value on day,
without having to change every use point
something like
#define log(level, area, xxx...) _log(level, SAL_AREA_ID ## area, xxx....)

Norbert


More information about the LibreOffice mailing list