Commit Graph

8 Commits

Author SHA1 Message Date
Thomas Haller
09dcb18381 shared: use NMStrBuf in _nm_utils_enum_to_str_full()
Just for showcase and to hit the code from the unit-tests
that we have.

Also, just to show, the following runs about 25 % faster than before,
which isn't bad for such a simple replacement.

    {
         GType gtype = nm_test_general_color_flags_get_type ();
         const int N_RUN = 1000000;
         int i_run;
         guint8 c = 0;

         for (i_run = 0; i_run < N_RUN; i_run++) {
              gs_free char *str = NULL;

              str = _nm_utils_enum_to_str_full (gtype, i_run % 10, ",", NULL);
              c += str[0];
         }
         return c % 3;
    }

$ perf stat -r 200 -B libnm-core/tests/test-general

Before:

 Performance counter stats for 'libnm-core/tests/test-general' (200 runs):

            204.48 msec task-clock:u              #    0.997 CPUs utilized            ( +-  0.53% )
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
               267      page-faults:u             #    0.001 M/sec                    ( +-  0.05% )
       702,987,494      cycles:u                  #    3.438 GHz                      ( +-  0.54% )
     1,698,874,415      instructions:u            #    2.42  insn per cycle           ( +-  0.00% )
       410,394,229      branches:u                # 2006.970 M/sec                    ( +-  0.00% )
         1,770,484      branch-misses:u           #    0.43% of all branches          ( +-  0.40% )

           0.20502 +- 0.00108 seconds time elapsed  ( +-  0.53% )

After:

 Performance counter stats for 'libnm-core/tests/test-general' (200 runs):

            155.71 msec task-clock:u              #    0.996 CPUs utilized            ( +-  0.50% )
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
               266      page-faults:u             #    0.002 M/sec                    ( +-  0.05% )
       539,994,118      cycles:u                  #    3.468 GHz                      ( +-  0.49% )
     1,116,016,733      instructions:u            #    2.07  insn per cycle           ( +-  0.00% )
       283,974,158      branches:u                # 1823.760 M/sec                    ( +-  0.00% )
         1,377,786      branch-misses:u           #    0.49% of all branches          ( +-  0.43% )

          0.156255 +- 0.000786 seconds time elapsed  ( +-  0.50% )
2020-04-03 11:31:12 +02:00
Thomas Haller
d5d7b4781e shared: pre-allocate GString with 16 bytes for _nm_utils_enum_to_str_full()
In the next commit, GString will be replaced by NMStrBuf. Then, we will
pre-allocate a string buffer with 16 bytes, and measure the performance
difference. To have it comparable, adjust the pre-allocation size also
with GString.
2020-04-03 11:31:12 +02:00
Thomas Haller
3b69f02164 all: unify format of our Copyright source code comments
```bash

readarray -d '' FILES < <(
  git ls-files -z \
    ':(exclude)po' \
    ':(exclude)shared/c-rbtree' \
    ':(exclude)shared/c-list' \
    ':(exclude)shared/c-siphash' \
    ':(exclude)shared/c-stdaux' \
    ':(exclude)shared/n-acd' \
    ':(exclude)shared/n-dhcp4' \
    ':(exclude)src/systemd/src' \
    ':(exclude)shared/systemd/src' \
    ':(exclude)m4' \
    ':(exclude)COPYING*'
  )

sed \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \
  -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \
  -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \
  -i \
  "${FILES[@]}"

echo ">>> untouched Copyright lines"
git grep Copyright "${FILES[@]}"

echo ">>> Copyright lines with unusual extra"
git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved

sed \
  -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \
  -i \
  "${FILES[@]}"

```

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
2019-10-02 17:03:52 +02:00
Thomas Haller
abff46cacf all: manually drop code comments with file description 2019-10-01 07:50:52 +02:00
Lubomir Rintel
24028a2246 all: SPDX header conversion
$ find * -type f |xargs perl contrib/scripts/spdx.pl
  $ git rm contrib/scripts/spdx.pl
2019-09-10 11:19:56 +02:00
Thomas Haller
c1e40a4f39 shared: use nm_auto_unref_gtypeclass in _nm_utils_enum_from_str_full() 2019-08-16 08:16:02 +02:00
Thomas Haller
c0e075c902 all: drop emacs file variables from source files
We no longer add these. If you use Emacs, configure it yourself.

Also, due to our "smart-tab" usage the editor anyway does a subpar
job handling our tabs. However, on the upside every user can choose
whatever tab-width he/she prefers. If "smart-tabs" are used properly
(like we do), every tab-width will work.

No manual changes, just ran commands:

    F=($(git grep -l -e '-\*-'))
    sed '1 { /\/\* *-\*-  *[mM]ode.*\*\/$/d }'     -i "${F[@]}"
    sed '1,4 { /^\(#\|--\|dnl\) *-\*- [mM]ode/d }' -i "${F[@]}"

Check remaining lines with:

    git grep -e '-\*-'

The ultimate purpose of this is to cleanup our files and eventually use
SPDX license identifiers. For that, first get rid of the boilerplate lines.
2019-06-11 10:04:00 +02:00
Thomas Haller
d984b2ce4a shared: move most of "shared/nm-utils" to "shared/nm-glib-aux"
From the files under "shared/nm-utils" we build an internal library
that provides glib-based helper utilities.

Move the files of that basic library to a new subdirectory
"shared/nm-glib-aux" and rename the helper library "libnm-core-base.la"
to "libnm-glib-aux.la".

Reasons:

 - the name "utils" is overused in our code-base. Everything's an
   "utils". Give this thing a more distinct name.

 - there were additional files under "shared/nm-utils", which are not
   part of this internal library "libnm-utils-base.la". All the files
   that are part of this library should be together in the same
   directory, but files that are not, should not be there.

 - the new name should better convey what this library is and what is isn't:
   it's a set of utilities and helper functions that extend glib with
   funcitonality that we commonly need.

There are still some files left under "shared/nm-utils". They have less
a unifying propose to be in their own directory, so I leave them there
for now. But at least they are separate from "shared/nm-glib-aux",
which has a very clear purpose.

(cherry picked from commit 80db06f768)
2019-04-18 19:57:27 +02:00