diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-04-25 11:36:36 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-04-27 15:29:27 +0000 |
commit | 654a5fe529cb09338b78f044296ac1445d590a0d (patch) | |
tree | 2deb0ddd72afa3e35679c802682f396d93875d62 /src/plugins/platforms/xcb | |
parent | 369572f892a5e748098c038b76b0f4331d2dd201 (diff) |
Optimize QXcbScreen::visualForFormat()
... by stopping the work when finding the first RGB candidate,
and otherwise only remembering the first candidate as a fall-back.
This way, we don't need to allocate memory as we did when collecting
the candidates in a QVector.
Saves more than 800b in text size on optimized GCC 6.0 Linux AMD64
builds.
Change-Id: I7d0cae69fa421fed881dd5a0f1aa45035d8f7461
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/plugins/platforms/xcb')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbscreen.cpp | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index b4c772dd3b..23585ab511 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -387,10 +387,9 @@ QSurfaceFormat QXcbScreen::surfaceFormatFor(const QSurfaceFormat &format) const const xcb_visualtype_t *QXcbScreen::visualForFormat(const QSurfaceFormat &format) const { - QVector<const xcb_visualtype_t *> candidates; + const xcb_visualtype_t *candidate = nullptr; - for (auto ii = m_visuals.constBegin(); ii != m_visuals.constEnd(); ++ii) { - const xcb_visualtype_t &xcb_visualtype = ii.value(); + for (const xcb_visualtype_t &xcb_visualtype : m_visuals) { const int redSize = qPopulationCount(xcb_visualtype.red_mask); const int greenSize = qPopulationCount(xcb_visualtype.green_mask); @@ -409,19 +408,17 @@ const xcb_visualtype_t *QXcbScreen::visualForFormat(const QSurfaceFormat &format if (format.alphaBufferSize() != -1 && alphaSize != format.alphaBufferSize()) continue; - candidates.append(&xcb_visualtype); - } - - if (candidates.isEmpty()) - return nullptr; + // Try to find a RGB visual rather than e.g. BGR or GBR + if (qCountTrailingZeroBits(xcb_visualtype.blue_mask) == 0) + return &xcb_visualtype; - // Try to find a RGB visual rather than e.g. BGR or GBR - for (const xcb_visualtype_t *candidate : qAsConst(candidates)) - if (qCountTrailingZeroBits(candidate->blue_mask) == 0) - return candidate; + // In case we do not find anything we like, just remember the first one + // and hope for the best: + if (!candidate) + candidate = &xcb_visualtype; + } - // Did not find anything we like, just grab the first one and hope for the best - return candidates.first(); + return candidate; } void QXcbScreen::sendStartupMessage(const QByteArray &message) const |