QLayoutPolicy: use qCountTrailingZeroBits() in setControlType()

This is more efficient, because it maps to a single assembler
instruction on most ISAs, and also avoids a Coverity warning about the
loop not terminating and thus 1 << i overflowing, if type == {}.

The clone class, QSizePolicy, is not affected, since it already uses
qCountTrailingZeroBits().

Amends 6c322a917ad57d57f0ee76825eab3e2e008c5bd4.

Coverity-Id: 474336
Pick-to: 6.8 6.5
Change-Id: Idf62d045d8ac3f0cb15196dd8664ac37d92a9cc2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit d71379d447e87843c5a5d91857c4ff253ad4b847)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-02-10 10:57:45 +01:00 committed by Qt Cherry-pick Bot
parent 21a0818903
commit 4ed56eaafc

View File

@ -22,15 +22,7 @@ void QLayoutPolicy::setControlType(ControlType type)
0x00000008 maps to 3
etc.
*/
int i = 0;
while (true) {
if (type & (0x1 << i)) {
bits.ctype = i;
return;
}
++i;
}
bits.ctype = qCountTrailingZeroBits(quint32(type));
}
QLayoutPolicy::ControlType QLayoutPolicy::controlType() const