QWaylandCursorTheme: replace a QMap with a C array

The QMap's key is an enumeration with small values (<= 33, as of this
writing), and while the range has a hole, it's not a terribly big one.

So, instead of using a QMap, just use a C array of mapped_type, using
the key as an index into the array. This gives a 'map' with zero
memory allocations.

It also saves a bit more than 700B in text size on optimized Linux
AMD64 GCC 9.1 builds.

Change-Id: If538ba80075f1bbdffd82b070e871391e6a5a6d1
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2019-07-21 18:55:01 +03:00
parent 4a47f124f5
commit f6155a7622
2 changed files with 6 additions and 4 deletions

View File

@ -74,7 +74,7 @@ QWaylandCursorTheme::~QWaylandCursorTheme()
wl_cursor *QWaylandCursorTheme::requestCursor(WaylandCursor shape)
{
if (struct wl_cursor *cursor = m_cursors.value(shape, nullptr))
if (struct wl_cursor *cursor = m_cursors[shape])
return cursor;
static Q_CONSTEXPR struct ShapeAndName {
@ -206,7 +206,7 @@ wl_cursor *QWaylandCursorTheme::requestCursor(WaylandCursor shape)
ShapeAndName{shape, ""}, byShape);
for (auto it = p.first; it != p.second; ++it) {
if (wl_cursor *cursor = wl_cursor_theme_get_cursor(m_theme, it->name)) {
m_cursors.insert(shape, cursor);
m_cursors[shape] = cursor;
return cursor;
}
}

View File

@ -109,13 +109,15 @@ private:
ResizeNorthWestCursor,
ResizeSouthEastCursor,
ResizeNorthEastCursor,
ResizeSouthWestCursor
ResizeSouthWestCursor,
NumWaylandCursors
};
explicit QWaylandCursorTheme(struct ::wl_cursor_theme *theme) : m_theme(theme) {}
struct ::wl_cursor *requestCursor(WaylandCursor shape);
struct ::wl_cursor_theme *m_theme = nullptr;
QMap<WaylandCursor, wl_cursor *> m_cursors;
wl_cursor *m_cursors[NumWaylandCursors] = {};
};
class Q_WAYLAND_CLIENT_EXPORT QWaylandCursor : public QPlatformCursor