summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-02-10 10:46:53 +0100
committerMarc Mutz <[email protected]>2025-03-13 21:40:43 +0000
commitbee49bde04777eae348aead0abc3212fa945c0ab (patch)
treea54cee78ca2087b95149ddf3ed65f0782943282d
parenta2e60ebee3737548d1be14fdbb39b08c515ae602 (diff)
qhighdpiscaling: de-pessimize optional<> use
std::optional::value_or() should not be used when its argument is a non-trivial type, because the argument is created and destroyed independent of whether it is used in the end. In this case, we don't even need an optional, because parseScreenScaleFactorsSpec() takes the output of qEnvironmentVariable() (not -OptionalString) as-is, so we can just drop the unneeded optional-(un)wrapping. Since this patch apparently removes the last user of qEnviromentVariableOptionalString(), mark that function as [[maybe_unused]]. Outright removal may cause cherry-picks to fail, so will come as a follow-up. Amends 4d1f13f3549a73f5ca4e64dac9137e83138080fa. Pick-to: 6.9 6.8 6.5 Change-Id: Ic2bb8a3aa8e946b957047ff4faf48c4082fc9c01 Reviewed-by: Ahmad Samir <[email protected]>
-rw-r--r--src/gui/kernel/qhighdpiscaling.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp
index 7bc2e0bc673..53dc6067418 100644
--- a/src/gui/kernel/qhighdpiscaling.cpp
+++ b/src/gui/kernel/qhighdpiscaling.cpp
@@ -28,6 +28,7 @@ static const char scaleFactorRoundingPolicyEnvVar[] = "QT_SCALE_FACTOR_ROUNDING_
static const char dpiAdjustmentPolicyEnvVar[] = "QT_DPI_ADJUSTMENT_POLICY";
static const char usePhysicalDpiEnvVar[] = "QT_USE_PHYSICAL_DPI";
+[[maybe_unused]]
static std::optional<QString> qEnvironmentVariableOptionalString(const char *name)
{
QString value = qEnvironmentVariable(name);
@@ -402,9 +403,9 @@ void QHighDpiScaling::initHighDpiScaling()
if (envScaleFactor.has_value())
qCDebug(lcHighDpi) << envDebugStr << scaleFactorEnvVar << envScaleFactor.value();
- std::optional<QString> envScreenFactors = qEnvironmentVariableOptionalString(screenFactorsEnvVar);
- if (envScreenFactors.has_value())
- qCDebug(lcHighDpi) << envDebugStr << screenFactorsEnvVar << envScreenFactors.value();
+ const QString envScreenFactors = qEnvironmentVariable(screenFactorsEnvVar);
+ if (envScreenFactors.isNull())
+ qCDebug(lcHighDpi) << envDebugStr << screenFactorsEnvVar << envScreenFactors;
std::optional envUsePhysicalDpi = qEnvironmentVariableIntegerValue(usePhysicalDpiEnvVar);
if (envUsePhysicalDpi.has_value())
@@ -429,8 +430,7 @@ void QHighDpiScaling::initHighDpiScaling()
// Store the envScreenFactors string for later use. The string format
// supports using screen names, which means that screen DPI cannot
// be resolved at this point.
- QString screenFactorsSpec = envScreenFactors.value_or(QString());
- m_screenFactors = parseScreenScaleFactorsSpec(QStringView{screenFactorsSpec});
+ m_screenFactors = parseScreenScaleFactorsSpec(envScreenFactors);
m_namedScreenScaleFactors.clear();
m_usePhysicalDpi = envUsePhysicalDpi.value_or(0) > 0;