[shotwell/shotwell-0.30] Cache setings schemas
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/shotwell-0.30] Cache setings schemas
- Date: Wed, 12 Sep 2018 11:56:01 +0000 (UTC)
commit 799bd6c97e9c33f554df77c7feb919240cd96b82
Author: Jens Georg <mail jensge org>
Date: Sat Sep 8 11:52:56 2018 +0200
Cache setings schemas
Do not relentlessly create settings chemas for every query to settings.
This seems to speed up things a bit and also make the random crashes
regarding settings_path_changed go away
Fixes #34
src/config/GSettingsEngine.vala | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
---
diff --git a/src/config/GSettingsEngine.vala b/src/config/GSettingsEngine.vala
index a1b830dd..a3d4e04e 100644
--- a/src/config/GSettingsEngine.vala
+++ b/src/config/GSettingsEngine.vala
@@ -25,6 +25,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private string[] schema_names;
private string[] key_names;
+ private Gee.HashMap<string, Settings> settings_cache = new Gee.HashMap<string, Settings>();
public GSettingsConfigurationEngine() {
schema_names = new string[ConfigurableProperty.NUM_PROPERTIES];
@@ -176,6 +177,14 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
key_names[ConfigurableProperty.VIDEO_INTERPRETER_STATE_COOKIE] = "interpreter-state-cookie";
}
+ private Settings get_settings(string schema) {
+ if (!this.settings_cache.has_key(schema)) {
+ this.settings_cache[schema] = new Settings(schema);
+ }
+
+ return this.settings_cache[schema];
+ }
+
private void check_key_valid(string schema, string key) throws ConfigurationError {
var schema_source = SettingsSchemaSource.get_default ();
var settings_scheme = schema_source.lookup (schema, true);
@@ -191,7 +200,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private bool get_gs_bool(string schema, string key) throws ConfigurationError {
check_key_valid(schema, key);
- Settings schema_object = new Settings(schema);
+ Settings schema_object = get_settings(schema);
return schema_object.get_boolean(key);
}
@@ -199,7 +208,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private void set_gs_bool(string schema, string key, bool value) throws ConfigurationError {
check_key_valid(schema, key);
- Settings schema_object = new Settings(schema);
+ Settings schema_object = get_settings(schema);
schema_object.set_boolean(key, value);
}
@@ -207,21 +216,21 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private void set_gs_enum (string schema, string key, int value) throws ConfigurationError {
check_key_valid (schema, key);
- var schema_object = new Settings (schema);
+ var schema_object = get_settings (schema);
schema_object.set_enum (key, value);
}
private int get_gs_enum (string schema, string key) throws ConfigurationError {
check_key_valid (schema, key);
- var schema_object = new Settings (schema);
+ var schema_object = get_settings (schema);
return schema_object.get_enum (key);
}
private int get_gs_int(string schema, string key) throws ConfigurationError {
check_key_valid(schema, key);
- Settings schema_object = new Settings(schema);
+ Settings schema_object = get_settings(schema);
return schema_object.get_int(key);
}
@@ -229,7 +238,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private void set_gs_int(string schema, string key, int value) throws ConfigurationError {
check_key_valid(schema, key);
- Settings schema_object = new Settings(schema);
+ Settings schema_object = get_settings(schema);
schema_object.set_int(key, value);
}
@@ -237,7 +246,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private double get_gs_double(string schema, string key) throws ConfigurationError {
check_key_valid(schema, key);
- Settings schema_object = new Settings(schema);
+ Settings schema_object = get_settings(schema);
return schema_object.get_double(key);
}
@@ -245,7 +254,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private void set_gs_double(string schema, string key, double value) throws ConfigurationError {
check_key_valid(schema, key);
- Settings schema_object = new Settings(schema);
+ Settings schema_object = get_settings(schema);
schema_object.set_double(key, value);
}
@@ -253,7 +262,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private string get_gs_string(string schema, string key) throws ConfigurationError {
check_key_valid(schema, key);
- Settings schema_object = new Settings(schema);
+ Settings schema_object = get_settings(schema);
return schema_object.get_string(key);
}
@@ -261,7 +270,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private void set_gs_string(string schema, string key, string value) throws ConfigurationError {
check_key_valid(schema, key);
- Settings schema_object = new Settings(schema);
+ Settings schema_object = get_settings(schema);
schema_object.set_string(key, value);
}
@@ -269,7 +278,7 @@ public class GSettingsConfigurationEngine : ConfigurationEngine, GLib.Object {
private void reset_gs_to_default(string schema, string key) throws ConfigurationError {
check_key_valid(schema, key);
- Settings schema_object = new Settings(schema);
+ Settings schema_object = get_settings(schema);
schema_object.reset(key);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]