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>
bb10
Marc Mutz 2016-04-25 11:36:36 +02:00
parent 369572f892
commit 654a5fe529
1 changed files with 11 additions and 14 deletions

View File

@ -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);
// Try to find a RGB visual rather than e.g. BGR or GBR
if (qCountTrailingZeroBits(xcb_visualtype.blue_mask) == 0)
return &xcb_visualtype;
// In case we do not find anything we like, just remember the first one
// and hope for the best:
if (!candidate)
candidate = &xcb_visualtype;
}
if (candidates.isEmpty())
return nullptr;
// 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;
// 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