[gnome-shell] cleanup: Minimize deep_unpack() usage
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] cleanup: Minimize deep_unpack() usage
- Date: Wed, 10 Aug 2022 10:33:07 +0000 (UTC)
commit ade4b2379696a23b9d53a52bb751521cdfe7667a
Author: Alessandro Bono <alessandro bono369 gmail com>
Date: Wed Aug 10 11:44:42 2022 +0200
cleanup: Minimize deep_unpack() usage
deep_unpack()[1] will unpack a variant and its children, but only up to one level.
lookup_value()[2] will directly search for a value with a linear scan.
Performing a deep_unpack() + lookup can be a more expensive operation when we are
looking for just a single value compared to just perform the lookup_value() directly
in C. Avoid the deep_unpack() usage when we perform a single check presence.
[1] https://gjs.guide/guides/glib/gvariant.html#deepunpack
[2] https://docs.gtk.org/glib/method.Variant.lookup_value.html
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2416>
js/gdm/realmd.js | 6 ++++--
js/misc/modemManager.js | 3 ++-
js/misc/smartcardManager.js | 3 ++-
js/ui/status/location.js | 4 ++--
js/ui/status/nightLight.js | 3 ++-
js/ui/status/powerProfiles.js | 13 ++++++-------
js/ui/status/thunderbolt.js | 11 +++++------
7 files changed, 23 insertions(+), 20 deletions(-)
---
diff --git a/js/gdm/realmd.js b/js/gdm/realmd.js
index e8220462ec..52661c1e54 100644
--- a/js/gdm/realmd.js
+++ b/js/gdm/realmd.js
@@ -28,7 +28,8 @@ var Manager = class extends Signals.EventEmitter {
this._aggregateProvider.connectObject('g-properties-changed',
(proxy, properties) => {
- if ('Realms' in properties.deep_unpack())
+ const realmsChanged = !!properties.lookup_value('Realms', null);
+ if (realmsChanged)
this._reloadRealms();
}, this);
}
@@ -67,7 +68,8 @@ var Manager = class extends Signals.EventEmitter {
this._reloadRealm(realm);
realm.connect('g-properties-changed', (proxy, properties) => {
- if ('Configured' in properties.deep_unpack())
+ const configuredChanged = !!properties.lookup_value('Configured', null);
+ if (configuredChanged)
this._reloadRealm(realm);
});
}
diff --git a/js/misc/modemManager.js b/js/misc/modemManager.js
index 0325ee6b34..0424b77ff9 100644
--- a/js/misc/modemManager.js
+++ b/js/misc/modemManager.js
@@ -243,7 +243,8 @@ var BroadbandModem = GObject.registerClass({
this._proxy_cdma = new BroadbandModemCdmaProxy(Gio.DBus.system, 'org.freedesktop.ModemManager1',
path);
this._proxy.connect('g-properties-changed', (proxy, properties) => {
- if ('SignalQuality' in properties.deep_unpack())
+ const signalQualityChanged = !!properties.lookup_value('SignalQuality', null);
+ if (signalQualityChanged)
this._reloadSignalQuality();
});
this._reloadSignalQuality();
diff --git a/js/misc/smartcardManager.js b/js/misc/smartcardManager.js
index 851cc445f8..661b337710 100644
--- a/js/misc/smartcardManager.js
+++ b/js/misc/smartcardManager.js
@@ -73,7 +73,8 @@ var SmartcardManager = class extends Signals.EventEmitter {
this._updateToken(token);
token.connect('g-properties-changed', (proxy, properties) => {
- if ('IsInserted' in properties.deep_unpack()) {
+ const isInsertedChanged = !!properties.lookup_value('IsInserted', null);
+ if (isInsertedChanged) {
this._updateToken(token);
if (token.IsInserted)
diff --git a/js/ui/status/location.js b/js/ui/status/location.js
index 116272d157..2115e5c231 100644
--- a/js/ui/status/location.js
+++ b/js/ui/status/location.js
@@ -181,8 +181,8 @@ var GeoclueAgent = GObject.registerClass({
}
_onGeocluePropsChanged(proxy, properties) {
- let unpacked = properties.deep_unpack();
- if ("InUse" in unpacked)
+ const inUseChanged = !!properties.lookup_value('InUse', null);
+ if (inUseChanged)
this.notify('in-use');
}
diff --git a/js/ui/status/nightLight.js b/js/ui/status/nightLight.js
index a7fa92a3fc..1a0ee303a3 100644
--- a/js/ui/status/nightLight.js
+++ b/js/ui/status/nightLight.js
@@ -49,7 +49,8 @@ class Indicator extends SystemIndicator {
g_interface_info: colorInfo,
});
this._proxy.connect('g-properties-changed', (p, properties) => {
- if ('NightLightActive' in properties.deep_unpack())
+ const nightLightActiveChanged = !!properties.lookup_value('NightLightActive', null);
+ if (nightLightActiveChanged)
this._sync();
});
this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
diff --git a/js/ui/status/powerProfiles.js b/js/ui/status/powerProfiles.js
index f1745e9953..43f6ce93f3 100644
--- a/js/ui/status/powerProfiles.js
+++ b/js/ui/status/powerProfiles.js
@@ -52,13 +52,12 @@ class PowerProfilesToggle extends QuickMenuToggle {
if (error) {
log(error.message);
} else {
- this._proxy.connect('g-properties-changed',
- (p, properties) => {
- const propertyNames = properties.deep_unpack();
- if ('Profiles' in propertyNames)
- this._syncProfiles();
- this._sync();
- });
+ this._proxy.connect('g-properties-changed', (p, properties) => {
+ const profilesChanged = !!properties.lookup_value('Profiles', null);
+ if (profilesChanged)
+ this._syncProfiles();
+ this._sync();
+ });
this._syncProfiles();
}
this._sync();
diff --git a/js/ui/status/thunderbolt.js b/js/ui/status/thunderbolt.js
index afe3a61958..2e1236e594 100644
--- a/js/ui/status/thunderbolt.js
+++ b/js/ui/status/thunderbolt.js
@@ -83,12 +83,11 @@ var Client = class extends Signals.EventEmitter {
}
_onPropertiesChanged(proxy, properties) {
- let unpacked = properties.deep_unpack();
- if (!('Probing' in unpacked))
- return;
-
- this.probing = this._proxy.Probing;
- this.emit('probing-changed', this.probing);
+ const probingChanged = !!properties.lookup_value('Probing', null);
+ if (probingChanged) {
+ this.probing = this._proxy.Probing;
+ this.emit('probing-changed', this.probing);
+ }
}
_onDeviceAdded(proxy, emitter, params) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]