summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-02-10 10:30:46 +0100
committerMarc Mutz <[email protected]>2025-02-14 05:45:02 +0000
commit8669bc97ff6811bae304a8bb2a0e3af2bb78cfe0 (patch)
tree9f504c12bc7ca6872926e4055ee3bbaef18df6a6
parent6c61d7b0f804ae5c048af95abef4d41ecc8862df (diff)
qhighdpiscaling: de-pessimize qEnvironmentVariableOptional*() functions
Don't call qEnvironmentVariableIsSet(), since it locks the environment mutex. Since qgetenv() and qEnvironmentVariable() both report whether the value was set (returning non-isNull()), we can avoid the extra mutex lock (and envvar lookup) by just calling those and then checking for isNull(). In qEnvironmentVariableOptionalReal(), in addition, use qgetenv() instead of qEnvironmentVariable(). While on Windows, that may convert encoding, QString::toDouble() first converts to Latin-1, and only then converts to double, so we avoid one encoding conversion, even on Windows; on Unix we avoid two. Amends 4d1f13f3549a73f5ca4e64dac9137e83138080fa. Pick-to: 6.9 6.8 6.5 Change-Id: I6803e2277b324c2568726765245681bcbf517362 Reviewed-by: Thiago Macieira <[email protected]> Reviewed-by: Ahmad Samir <[email protected]>
-rw-r--r--src/gui/kernel/qhighdpiscaling.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp
index 3d518409a9e..6fead184c2a 100644
--- a/src/gui/kernel/qhighdpiscaling.cpp
+++ b/src/gui/kernel/qhighdpiscaling.cpp
@@ -30,18 +30,14 @@ static const char usePhysicalDpiEnvVar[] = "QT_USE_PHYSICAL_DPI";
static std::optional<QString> qEnvironmentVariableOptionalString(const char *name)
{
- if (!qEnvironmentVariableIsSet(name))
- return std::nullopt;
-
- return std::optional(qEnvironmentVariable(name));
+ QString value = qEnvironmentVariable(name);
+ return value.isNull() ? std::nullopt : std::optional(std::move(value));
}
static std::optional<QByteArray> qEnvironmentVariableOptionalByteArray(const char *name)
{
- if (!qEnvironmentVariableIsSet(name))
- return std::nullopt;
-
- return std::optional(qgetenv(name));
+ QByteArray value = qgetenv(name);
+ return value.isNull() ? std::nullopt : std::optional(std::move(value));
}
static std::optional<int> qEnvironmentVariableOptionalInt(const char *name)
@@ -54,11 +50,12 @@ static std::optional<int> qEnvironmentVariableOptionalInt(const char *name)
static std::optional<qreal> qEnvironmentVariableOptionalReal(const char *name)
{
- if (!qEnvironmentVariableIsSet(name))
+ const QByteArray val = qgetenv(name);
+ if (val.isNull())
return std::nullopt;
bool ok = false;
- const qreal value = qEnvironmentVariable(name).toDouble(&ok);
+ const qreal value = val.toDouble(&ok);
return ok ? std::optional(value) : std::nullopt;
}