diff options
author | Richard Hughes <richard@hughsie.com> | 2016-11-03 17:28:44 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2016-11-03 17:28:44 +0000 |
commit | 9c488cd3b4d043a1c8cad5a8760ab724cdec2e84 (patch) | |
tree | 60e689e5e5cf5195208b5bd64e40abaf4c365832 | |
parent | e820ab1fec6a8fdedd5931c7681d9a59094a289e (diff) | |
download | appstream-glib-9c488cd3b4d043a1c8cad5a8760ab724cdec2e84.tar.gz |
trivial: Only load native languages from desktop files when the flag is set
This saves 40ms from the AsStore startup time.
-rw-r--r-- | libappstream-glib/as-app-desktop.c | 12 | ||||
-rw-r--r-- | libappstream-glib/as-app.h | 18 | ||||
-rw-r--r-- | libappstream-glib/as-store.c | 4 |
3 files changed, 26 insertions, 8 deletions
diff --git a/libappstream-glib/as-app-desktop.c b/libappstream-glib/as-app-desktop.c index 0f78b5b..c4cc099 100644 --- a/libappstream-glib/as-app-desktop.c +++ b/libappstream-glib/as-app-desktop.c @@ -284,6 +284,9 @@ as_app_parse_file_key (AsApp *app, } else if (g_str_has_prefix (key, "Keywords")) { locale = as_app_desktop_key_get_locale (key); + if (flags & AS_APP_PARSE_FLAG_ONLY_NATIVE_LANGS && + !g_strv_contains (g_get_language_names (), locale)) + return TRUE; list = g_key_file_get_locale_string_list (kf, G_KEY_FILE_DESKTOP_GROUP, key, @@ -338,6 +341,9 @@ as_app_parse_file_key (AsApp *app, /* Name[] */ } else if (g_str_has_prefix (key, G_KEY_FILE_DESKTOP_KEY_NAME)) { locale = as_app_desktop_key_get_locale (key); + if (flags & AS_APP_PARSE_FLAG_ONLY_NATIVE_LANGS && + !g_strv_contains (g_get_language_names (), locale)) + return TRUE; tmp = g_key_file_get_locale_string (kf, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, @@ -359,6 +365,9 @@ as_app_parse_file_key (AsApp *app, /* Comment[] */ } else if (g_str_has_prefix (key, G_KEY_FILE_DESKTOP_KEY_COMMENT)) { locale = as_app_desktop_key_get_locale (key); + if (flags & AS_APP_PARSE_FLAG_ONLY_NATIVE_LANGS && + !g_strv_contains (g_get_language_names (), locale)) + return TRUE; tmp = g_key_file_get_locale_string (kf, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, @@ -377,6 +386,9 @@ as_app_parse_file_key (AsApp *app, as_app_set_name (app, "C", tmp); } else if (g_str_has_prefix (key, "X-Ubuntu-Software-Center-Name")) { locale = as_app_desktop_key_get_locale (key); + if (flags & AS_APP_PARSE_FLAG_ONLY_NATIVE_LANGS && + !g_strv_contains (g_get_language_names (), locale)) + return TRUE; tmp = g_key_file_get_locale_string (kf, G_KEY_FILE_DESKTOP_GROUP, "X-Ubuntu-Software-Center-Name", diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h index 02c87d2..a67129a 100644 --- a/libappstream-glib/as-app.h +++ b/libappstream-glib/as-app.h @@ -68,18 +68,20 @@ struct _AsAppClass * @AS_APP_PARSE_FLAG_ALLOW_VETO: Do not return errors for vetoed apps * @AS_APP_PARSE_FLAG_USE_FALLBACKS: Fall back to suboptimal data where required * @AS_APP_PARSE_FLAG_ADD_ALL_METADATA: Add all extra metadata from the source file + * @AS_APP_PARSE_FLAG_ONLY_NATIVE_LANGS: Only load native languages * * The flags to use when parsing resources. **/ typedef enum { - AS_APP_PARSE_FLAG_NONE, - AS_APP_PARSE_FLAG_USE_HEURISTICS = 1, /* Since: 0.1.2 */ - AS_APP_PARSE_FLAG_KEEP_COMMENTS = 2, /* Since: 0.1.6 */ - AS_APP_PARSE_FLAG_CONVERT_TRANSLATABLE = 4, /* Since: 0.1.6 */ - AS_APP_PARSE_FLAG_APPEND_DATA = 8, /* Since: 0.1.8 */ - AS_APP_PARSE_FLAG_ALLOW_VETO = 16, /* Since: 0.2.5 */ - AS_APP_PARSE_FLAG_USE_FALLBACKS = 32, /* Since: 0.4.1 */ - AS_APP_PARSE_FLAG_ADD_ALL_METADATA = 64, /* Since: 0.6.1 */ + AS_APP_PARSE_FLAG_NONE = 0, + AS_APP_PARSE_FLAG_USE_HEURISTICS = 1 << 0, /* Since: 0.1.2 */ + AS_APP_PARSE_FLAG_KEEP_COMMENTS = 1 << 1, /* Since: 0.1.6 */ + AS_APP_PARSE_FLAG_CONVERT_TRANSLATABLE = 1 << 2, /* Since: 0.1.6 */ + AS_APP_PARSE_FLAG_APPEND_DATA = 1 << 3, /* Since: 0.1.8 */ + AS_APP_PARSE_FLAG_ALLOW_VETO = 1 << 4, /* Since: 0.2.5 */ + AS_APP_PARSE_FLAG_USE_FALLBACKS = 1 << 5, /* Since: 0.4.1 */ + AS_APP_PARSE_FLAG_ADD_ALL_METADATA = 1 << 6, /* Since: 0.6.1 */ + AS_APP_PARSE_FLAG_ONLY_NATIVE_LANGS = 1 << 7, /* Since: 0.6.3 */ /*< private >*/ AS_APP_PARSE_FLAG_LAST, } AsAppParseFlags; diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c index 158b727..ff87915 100644 --- a/libappstream-glib/as-store.c +++ b/libappstream-glib/as-store.c @@ -2669,6 +2669,10 @@ as_store_load_installed (AsStore *store, if (flags & AS_STORE_LOAD_FLAG_ALLOW_VETO) parse_flags |= AS_APP_PARSE_FLAG_ALLOW_VETO; + /* propagate flag */ + if (priv->add_flags & AS_STORE_ADD_FLAG_ONLY_NATIVE_LANGS) + parse_flags |= AS_APP_PARSE_FLAG_ONLY_NATIVE_LANGS; + while ((tmp = g_dir_read_name (dir)) != NULL) { AsApp *app_tmp; GPtrArray *icons; |