From 62be4ab5be41b09eea16e5675ed4a74c795e58d9 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 2 Feb 2023 01:34:08 +0100 Subject: [PATCH] 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 Reviewed-by: Liang Qi Reviewed-by: Shawn Rutledge --- src/plugins/platforms/xcb/qxcbatom.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbatom.cpp b/src/plugins/platforms/xcb/qxcbatom.cpp index 6cb6d29de24..09b1fe8a9d0 100644 --- a/src/plugins/platforms/xcb/qxcbatom.cpp +++ b/src/plugins/platforms/xcb/qxcbatom.cpp @@ -215,25 +215,19 @@ 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; + 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); - xcb_intern_atom_cookie_t cookies[QXcbAtom::NAtoms]; - - 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); m_allAtoms[i] = reply->atom;