From 4ed56eaafcc6270855b305d08d551f6a48c9667b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 10 Feb 2025 10:57:45 +0100 Subject: [PATCH] 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 (cherry picked from commit d71379d447e87843c5a5d91857c4ff253ad4b847) Reviewed-by: Qt Cherry-pick Bot --- src/gui/util/qlayoutpolicy.cpp | 10 +--------- 1 file changed, 1 insertion(+), 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