diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-02-02 01:34:08 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-02-07 18:59:59 +0100 |
commit | 62be4ab5be41b09eea16e5675ed4a74c795e58d9 (patch) | |
tree | 8f55e1c8dd1972a3ae1c0364049bb0d57259c389 /src/plugins | |
parent | 3d72e8829fb9ebcd3b1179b54ad4053de05368ff (diff) |
XCB: simplify atom registration code
There's no need of calculating offsets into the \0-separated string
of atom names; since we're going to iterate that string exactly once,
do that, and register the corresponding atom name as we iterate.
(This means that solutions that calculate the offsets at compile-time,
like qOffsetStringArray, are also overkill for the use case).
Change-Id: I71ed512dee4f2a8bfb99ca2392efbd8a07f2a7c1
Reviewed-by: JiDe Zhang <zhangjide@uniontech.com>
Reviewed-by: Liang Qi <liang.qi@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbatom.cpp | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/plugins/platforms/xcb/qxcbatom.cpp b/src/plugins/platforms/xcb/qxcbatom.cpp index 6cb6d29de2..09b1fe8a9d 100644 --- a/src/plugins/platforms/xcb/qxcbatom.cpp +++ b/src/plugins/platforms/xcb/qxcbatom.cpp @@ -215,24 +215,18 @@ void QXcbAtom::initialize(xcb_connection_t *connection) } void QXcbAtom::initializeAllAtoms(xcb_connection_t *connection) { - const char *names[QXcbAtom::NAtoms]; - const char *ptr = xcb_atomnames; - + const char *name = xcb_atomnames; + size_t name_len; int i = 0; - while (*ptr) { - names[i++] = ptr; - while (*ptr) - ++ptr; - ++ptr; - } - - Q_ASSERT(i == QXcbAtom::NAtoms); - xcb_intern_atom_cookie_t cookies[QXcbAtom::NAtoms]; + while ((name_len = strlen(name)) != 0) { + cookies[i] = xcb_intern_atom(connection, false, name_len, name); + ++i; + name += name_len + 1; // jump over the \0 + } + Q_ASSERT(i == QXcbAtom::NAtoms); - for (i = 0; i < QXcbAtom::NAtoms; ++i) - cookies[i] = xcb_intern_atom(connection, false, strlen(names[i]), names[i]); for (i = 0; i < QXcbAtom::NAtoms; ++i) { xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookies[i], nullptr); |