summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-tag.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-03-18 17:43:00 +0000
committerRichard Hughes <richard@hughsie.com>2014-03-18 17:43:00 +0000
commit3c72fb9ab4fafc812801f2dfc50266874bbc8cfc (patch)
treeda0f530ff609947cdd59a29ac68ba71c664b6c26 /libappstream-glib/as-tag.c
parent5ce0c0b019b8161c1ddf6bbe0f13f08627f0df10 (diff)
downloadappstream-glib-3c72fb9ab4fafc812801f2dfc50266874bbc8cfc.tar.gz
Speed up as_tag_to_string() by using a table and a single lookup
Diffstat (limited to 'libappstream-glib/as-tag.c')
-rw-r--r--libappstream-glib/as-tag.c96
1 files changed, 35 insertions, 61 deletions
diff --git a/libappstream-glib/as-tag.c b/libappstream-glib/as-tag.c
index 3144da9..7dc6aec 100644
--- a/libappstream-glib/as-tag.c
+++ b/libappstream-glib/as-tag.c
@@ -130,65 +130,39 @@ as_tag_from_string (const gchar *tag)
const gchar *
as_tag_to_string (AsTag tag)
{
- if (tag == AS_TAG_APPLICATIONS)
- return "applications";
- if (tag == AS_TAG_APPLICATION)
- return "application";
- if (tag == AS_TAG_ID)
- return "id";
- if (tag == AS_TAG_PKGNAME)
- return "pkgname";
- if (tag == AS_TAG_NAME)
- return "name";
- if (tag == AS_TAG_SUMMARY)
- return "summary";
- if (tag == AS_TAG_PROJECT_GROUP)
- return "project_group";
- if (tag == AS_TAG_URL)
- return "url";
- if (tag == AS_TAG_DESCRIPTION)
- return "description";
- if (tag == AS_TAG_ICON)
- return "icon";
- if (tag == AS_TAG_CATEGORIES)
- return "categories";
- if (tag == AS_TAG_CATEGORY)
- return "category";
- if (tag == AS_TAG_KEYWORDS)
- return "keywords";
- if (tag == AS_TAG_KEYWORD)
- return "keyword";
- if (tag == AS_TAG_MIMETYPES)
- return "mimetypes";
- if (tag == AS_TAG_MIMETYPE)
- return "mimetype";
- if (tag == AS_TAG_PROJECT_LICENSE)
- return "project_license";
- if (tag == AS_TAG_SCREENSHOTS)
- return "screenshots";
- if (tag == AS_TAG_SCREENSHOT)
- return "screenshot";
- if (tag == AS_TAG_UPDATE_CONTACT)
- return "updatecontact";
- if (tag == AS_TAG_IMAGE)
- return "image";
- if (tag == AS_TAG_COMPULSORY_FOR_DESKTOP)
- return "compulsory_for_desktop";
- if (tag == AS_TAG_PRIORITY)
- return "priority";
- if (tag == AS_TAG_CAPTION)
- return "caption";
- if (tag == AS_TAG_LANGUAGES)
- return "languages";
- if (tag == AS_TAG_LANG)
- return "lang";
- if (tag == AS_TAG_METADATA)
- return "metadata";
- if (tag == AS_TAG_VALUE)
- return "value";
- if (tag == AS_TAG_RELEASES)
- return "releases";
- if (tag == AS_TAG_RELEASE)
- return "release";
- return NULL;
+ const gchar *str[] = {
+ "applications",
+ "application",
+ "id",
+ "pkgname",
+ "name",
+ "summary",
+ "project_group",
+ "url",
+ "description",
+ "icon",
+ "categories",
+ "category",
+ "keywords",
+ "keyword",
+ "mimetypes",
+ "mimetype",
+ "project_license",
+ "screenshots",
+ "screenshot",
+ "updatecontact",
+ "image",
+ "compulsory_for_desktop",
+ "priority",
+ "caption",
+ "languages",
+ "lang",
+ "metadata",
+ "value",
+ "releases",
+ "release",
+ NULL };
+ if (tag > AS_TAG_LAST)
+ tag = AS_TAG_LAST;
+ return str[tag];
}