[gjs/gnome-3-34] Gio override: optimize constructor param checks in _init



commit 16bd54e766879bbf55471502f12d750ecda60a9c
Author: Andy Holmes <andrew g r holmes gmail com>
Date:   Mon Dec 2 20:32:12 2019 -0800

    Gio override: optimize constructor param checks in _init

 modules/overrides/Gio.js | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
---
diff --git a/modules/overrides/Gio.js b/modules/overrides/Gio.js
index a2489c6f..caf46ab6 100644
--- a/modules/overrides/Gio.js
+++ b/modules/overrides/Gio.js
@@ -534,21 +534,18 @@ function _init() {
         _realInit: Gio.Settings.prototype._init,  // add manually, not enumerable
         _init(props = {}) {
             // 'schema' is a deprecated alias for schema_id
-            const requiredProps = ['schema', 'schema-id', 'schema_id', 'schemaId',
-                'settings-schema', 'settings_schema', 'settingsSchema'];
-            if (requiredProps.every(prop => !(prop in props))) {
+            const schemaIdProp = ['schema', 'schema-id', 'schema_id',
+                'schemaId'].find(prop => prop in props);
+            const settingsSchemaProp = ['settings-schema', 'settings_schema',
+                'settingsSchema'].find(prop => prop in props);
+            if (!schemaIdProp && !settingsSchemaProp) {
                 throw new Error('One of property \'schema-id\' or ' +
                     '\'settings-schema\' are required for Gio.Settings');
             }
 
-            const checkSchemasProps = ['schema', 'schema-id', 'schema_id', 'schemaId'];
             const source = Gio.SettingsSchemaSource.get_default();
-            for (const prop of checkSchemasProps) {
-                if (!(prop in props))
-                    continue;
-                if (source.lookup(props[prop], true) === null)
-                    throw new Error(`GSettings schema ${props[prop]} not found`);
-            }
+            if (schemaIdProp && !source.lookup(props[schemaIdProp], true))
+                throw new Error(`GSettings schema ${props[schemaIdProp]} not found`);
 
             return this._realInit(props);
         },


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]