Commit 767ade02 authored by Max Kellermann's avatar Max Kellermann

tag_table: convert to a struct

The struct is smaller because it is sparse. Its traversal is also more efficient.
parent 6e05071a
...@@ -356,16 +356,17 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream) ...@@ -356,16 +356,17 @@ mp4_decode(struct decoder *mpd_decoder, struct input_stream *input_stream)
mp4ff_close(mp4fh); mp4ff_close(mp4fh);
} }
static const char *const mp4ff_tag_names[TAG_NUM_OF_ITEM_TYPES] = { static const struct tag_table mp4ff_tags[] = {
[TAG_ALBUM_ARTIST] = "album artist", { "album artist", TAG_ALBUM_ARTIST },
[TAG_COMPOSER] = "writer", { "writer", TAG_COMPOSER },
[TAG_PERFORMER] = "band", { "band", TAG_PERFORMER },
{ NULL, TAG_NUM_OF_ITEM_TYPES }
}; };
static enum tag_type static enum tag_type
mp4ff_tag_name_parse(const char *name) mp4ff_tag_name_parse(const char *name)
{ {
enum tag_type type = tag_table_lookup(mp4ff_tag_names, name); enum tag_type type = tag_table_lookup_i(mp4ff_tags, name);
if (type == TAG_NUM_OF_ITEM_TYPES) if (type == TAG_NUM_OF_ITEM_TYPES)
type = tag_name_parse_i(name); type = tag_name_parse_i(name);
......
...@@ -23,15 +23,16 @@ ...@@ -23,15 +23,16 @@
#include "tag_table.h" #include "tag_table.h"
#include "ape.h" #include "ape.h"
static const char *const ape_tag_names[TAG_NUM_OF_ITEM_TYPES] = { static const struct tag_table ape_tags[] = {
[TAG_ALBUM_ARTIST] = "album artist", { "album artist", TAG_ALBUM_ARTIST },
[TAG_DATE] = "year", { "year", TAG_DATE },
{ NULL, TAG_NUM_OF_ITEM_TYPES }
}; };
static enum tag_type static enum tag_type
tag_ape_name_parse(const char *name) tag_ape_name_parse(const char *name)
{ {
enum tag_type type = tag_table_lookup(ape_tag_names, name); enum tag_type type = tag_table_lookup_i(ape_tags, name);
if (type == TAG_NUM_OF_ITEM_TYPES) if (type == TAG_NUM_OF_ITEM_TYPES)
type = tag_name_parse_i(name); type = tag_name_parse_i(name);
......
...@@ -24,18 +24,24 @@ ...@@ -24,18 +24,24 @@
#include <glib.h> #include <glib.h>
struct tag_table {
const char *name;
enum tag_type type;
};
/** /**
* Looks up a string in a tag translation table (case insensitive). * Looks up a string in a tag translation table (case insensitive).
* Returns TAG_NUM_OF_ITEM_TYPES if the specified name was not found * Returns TAG_NUM_OF_ITEM_TYPES if the specified name was not found
* in the table. * in the table.
*/ */
G_GNUC_PURE
static inline enum tag_type static inline enum tag_type
tag_table_lookup(const char *const* table, const char *name) tag_table_lookup_i(const struct tag_table *table, const char *name)
{ {
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) for (; table->name != NULL; ++table)
if (table[i] != NULL && if (g_ascii_strcasecmp(name, table->name) == 0)
g_ascii_strcasecmp(name, table[i]) == 0) return table->type;
return (enum tag_type)i;
return TAG_NUM_OF_ITEM_TYPES; return TAG_NUM_OF_ITEM_TYPES;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment