summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKalev Lember <klember@redhat.com>2017-01-30 12:46:50 +0100
committerKalev Lember <klember@redhat.com>2017-01-30 12:51:41 +0100
commit5b10dcf4d5591451b54ecbeee694e5f4945c8f63 (patch)
treeb8655098901e216efe7d633c194013920d07fd25
parentdb36ef4922d985c3789081ed2d842dd6d3d5c1b0 (diff)
downloadappstream-glib-wip/kalev/gperf31.tar.gz
Move more gperf lookup code into the generated gperf filewip/kalev/gperf31
-rw-r--r--libappstream-glib/as-tag.c8
-rw-r--r--libappstream-glib/as-tag.gperf14
2 files changed, 15 insertions, 7 deletions
diff --git a/libappstream-glib/as-tag.c b/libappstream-glib/as-tag.c
index bd78939..83b2761 100644
--- a/libappstream-glib/as-tag.c
+++ b/libappstream-glib/as-tag.c
@@ -75,9 +75,7 @@ as_tag_from_string (const gchar *tag)
AsTag
as_tag_from_string_full (const gchar *tag, AsTagFlags flags)
{
-#ifdef HAVE_GPERF
- const struct tag_data *ky;
-#else
+#ifndef HAVE_GPERF
guint i;
#endif
AsTag etag = AS_TAG_UNKNOWN;
@@ -88,9 +86,7 @@ as_tag_from_string_full (const gchar *tag, AsTagFlags flags)
#ifdef HAVE_GPERF
/* use a perfect hash */
- ky = _as_tag_from_gperf (tag, (guint) strlen (tag));
- if (ky != NULL)
- etag = ky->etag;
+ etag = _as_tag_from_gperf (tag);
#else
for (i = 0; i < AS_TAG_LAST; i++) {
if (g_strcmp0 (tag, as_tag_to_string (i)) == 0) {
diff --git a/libappstream-glib/as-tag.gperf b/libappstream-glib/as-tag.gperf
index f002ee0..3898d55 100644
--- a/libappstream-glib/as-tag.gperf
+++ b/libappstream-glib/as-tag.gperf
@@ -1,7 +1,7 @@
%language=ANSI-C
%struct-type
%define hash-function-name _as_tag_hash
-%define lookup-function-name _as_tag_from_gperf
+%define lookup-function-name _as_tag_lookup
%readonly-tables
%includes
%pic
@@ -66,3 +66,15 @@ reviewer_id, AS_TAG_REVIEWER_ID
suggests, AS_TAG_SUGGESTS
requires, AS_TAG_REQUIRES
custom, AS_TAG_CUSTOM
+%%
+static AsTag
+_as_tag_from_gperf (const char *tag)
+{
+ const struct tag_data *ky;
+
+ ky = _as_tag_lookup (tag, strlen (tag));
+ if (ky != NULL)
+ return ky->etag;
+
+ return AS_TAG_UNKNOWN;
+}