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>
This commit is contained in:
parent
3d72e8829f
commit
62be4ab5be
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user