Improve handling changed properties in `SyncthingService`
* Check directly whether changed properties contain a property instead of checking indirectly whether the returned QVariant is invalid. * Avoid copying the QVariant. * Effectively this should not change anything; the code is just more readable and possibly more efficient.
This commit is contained in:
parent
f524a18b83
commit
76209e2922
|
@ -550,11 +550,11 @@ void SyncthingService::handlePrepareForSleep(bool rightBefore)
|
||||||
bool SyncthingService::handlePropertyChanged(QString &variable, void (SyncthingService::*signal)(const QString &), const QString &propertyName,
|
bool SyncthingService::handlePropertyChanged(QString &variable, void (SyncthingService::*signal)(const QString &), const QString &propertyName,
|
||||||
const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
|
const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
|
||||||
{
|
{
|
||||||
const QVariant valueVariant(changedProperties[propertyName]);
|
const auto valueVariant = changedProperties.find(propertyName);
|
||||||
if (valueVariant.isValid()) {
|
if (valueVariant != changedProperties.end()) {
|
||||||
const QString valueString(valueVariant.toString());
|
auto valueString = valueVariant->toString();
|
||||||
if (valueString != variable) {
|
if (valueString != variable) {
|
||||||
emit(this->*signal)(variable = valueString);
|
emit(this->*signal)(variable = std::move(valueString));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (invalidatedProperties.contains(propertyName) && !variable.isEmpty()) {
|
} else if (invalidatedProperties.contains(propertyName) && !variable.isEmpty()) {
|
||||||
|
@ -571,10 +571,10 @@ bool SyncthingService::handlePropertyChanged(QString &variable, void (SyncthingS
|
||||||
bool SyncthingService::handlePropertyChanged(
|
bool SyncthingService::handlePropertyChanged(
|
||||||
DateTime &variable, const QString &propertyName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
|
DateTime &variable, const QString &propertyName, const QVariantMap &changedProperties, const QStringList &invalidatedProperties)
|
||||||
{
|
{
|
||||||
const QVariant valueVariant(changedProperties[propertyName]);
|
const auto valueVariant = changedProperties.find(propertyName);
|
||||||
if (valueVariant.isValid()) {
|
if (valueVariant != changedProperties.end()) {
|
||||||
bool ok;
|
bool ok;
|
||||||
const qulonglong valueInt = valueVariant.toULongLong(&ok);
|
const qulonglong valueInt = valueVariant->toULongLong(&ok);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
variable = dateTimeFromSystemdTimeStamp(valueInt);
|
variable = dateTimeFromSystemdTimeStamp(valueInt);
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue