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>
This commit is contained in:
Alessandro Bono
2022-08-10 11:44:42 +02:00
committed by Marge Bot
parent 23bfd08b3c
commit ade4b23796
7 changed files with 23 additions and 20 deletions

View File

@ -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);
});
}