diff options
author | Marc Mutz <[email protected]> | 2025-02-10 10:57:45 +0100 |
---|---|---|
committer | Marc Mutz <[email protected]> | 2025-02-13 15:15:27 +0100 |
commit | d71379d447e87843c5a5d91857c4ff253ad4b847 (patch) | |
tree | 1e1d2389383860722f11c85fbfe4f552dfc4821d | |
parent | 6e089a66a4d08a5d788c194560fccdec793e6337 (diff) |
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.9 6.8 6.5
Change-Id: Idf62d045d8ac3f0cb15196dd8664ac37d92a9cc2
Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r-- | src/gui/util/qlayoutpolicy.cpp | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/src/gui/util/qlayoutpolicy.cpp b/src/gui/util/qlayoutpolicy.cpp index 2e3a0b32cb5..3e6cb27c1b7 100644 --- a/src/gui/util/qlayoutpolicy.cpp +++ b/src/gui/util/qlayoutpolicy.cpp @@ -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 |