From 5edb9a6a0fafc14717a3a8196ab67cff9ea4d54d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 10 Apr 2024 10:00:01 -0700 Subject: [PATCH] QStringBuilder: DRY: simplify the if constexpr conditionals a bit Both sides of it were calling the same appendTo(), so we can avoid repeating ourselves. This MAY fix a warning with VS2019. Fixes: QTBUG-124117 Change-Id: I40526efc4e93413794c3fffd17c4f9c96ee187f9 Reviewed-by: Giuseppe D'Angelo (cherry picked from commit 2e8c6d467fa245e8bcb81cff63d2d9628e1ee81e) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qstringbuilder.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/corelib/text/qstringbuilder.h b/src/corelib/text/qstringbuilder.h index 17160c65b61..258ab2f4572 100644 --- a/src/corelib/text/qstringbuilder.h +++ b/src/corelib/text/qstringbuilder.h @@ -109,18 +109,17 @@ private: // both QString and QByteArray's data() and constData(). The result is // the same if len != 0. auto d = reinterpret_cast(s.data_ptr().data()); + const auto start = d; + QConcatenable>::appendTo(*this, d); if constexpr (QConcatenable>::ExactSize) { - QConcatenable>::appendTo(*this, d); - return s; - } - - typename T::const_iterator const start = d; - QConcatenable>::appendTo(*this, d); - if (len != d - start) { - // this resize is necessary since we allocate a bit too much - // when dealing with variable sized 8-bit encodings - s.resize(d - start); + Q_UNUSED(start) + } else { + if (len != d - start) { + // this resize is necessary since we allocate a bit too much + // when dealing with variable sized 8-bit encodings + s.resize(d - start); + } } return s; }