summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2022-03-13 01:36:52 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2022-03-13 01:40:42 -0500
commita9c62f2c39a74ccfc05fa7160efade49286da77c (patch)
treee429a1b9eeed44f2956b38f518c52f7d3b50b90c
parent22a6ae97a6e04161ad52397002e041b53313228d (diff)
downloadrockbox-a9c62f2c39.tar.gz
rockbox-a9c62f2c39.zip
metadata_common.c optimize parse_tag
Change-Id: I84ad404fdcc9698b9d08e6e9c37929f4b7bf569f
-rw-r--r--lib/rbcodec/metadata/metadata_common.c78
1 files changed, 50 insertions, 28 deletions
diff --git a/lib/rbcodec/metadata/metadata_common.c b/lib/rbcodec/metadata/metadata_common.c
index 6fc50e9a9d..3677599c30 100644
--- a/lib/rbcodec/metadata/metadata_common.c
+++ b/lib/rbcodec/metadata/metadata_common.c
@@ -252,6 +252,22 @@ bool skip_id3v2(int fd, struct mp3entry *id3)
return success;
}
+static int get_tag_option(const char *option, const char *const oplist[])
+{
+ int i;
+ int ifound = -1;
+ const char *op;
+ for (i=0; (op=oplist[i]) != NULL; i++)
+ {
+ if (strcasecmp(op, option) == 0)
+ {
+ ifound = i;
+ break;
+ }
+ }
+ return ifound;
+}
+
/* Parse the tag (the name-value pair) and fill id3 and buffer accordingly.
* String values to keep are written to buf. Returns number of bytes written
* to buf (including end nil).
@@ -262,19 +278,38 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
long len = 0;
char** p;
- if ((((strcasecmp(name, "track") == 0) && (type == TAGTYPE_APE)))
- || ((strcasecmp(name, "tracknumber") == 0) && (type == TAGTYPE_VORBIS)))
+ enum
+ {
+ eTRACK = 0, eTRACKNUMBER, eDISCNUMBER, eDISC,
+ eYEAR, eDATE, eTITLE, eARTIST, eALBUM, eGENRE,
+ eCOMPOSER, eCOMMENT, eALBUMARTIST, eALBUM_ARTIST,
+ eENSEMBLE, eGROUPING, eCONTENTGROUP, eCONTENT_GROUP,
+ eMUSICBRAINZ1, eMUSICBRAINZ2
+ };
+
+ const char *tagops[] =
+ { "track", "tracknumber", "discnumber", "disc",
+ "year","date","title", "artist", "album", "genre"
+ "composer","comment","albumartist","album artist",
+ "ensemble","grouping","contentgroup","content group",
+ "musicbrainz_trackid", "http://musicbrainz.org", NULL
+ };
+
+ int item = get_tag_option(name, tagops);
+
+ if (((item == eTRACK && (type == TAGTYPE_APE)))
+ || (item == eTRACKNUMBER && (type == TAGTYPE_VORBIS)))
{
id3->tracknum = atoi(value);
p = &(id3->track_string);
}
- else if (strcasecmp(name, "discnumber") == 0 || strcasecmp(name, "disc") == 0)
+ else if (item == eDISCNUMBER || item == eDISC)
{
id3->discnum = atoi(value);
p = &(id3->disc_string);
}
- else if (((strcasecmp(name, "year") == 0) && (type == TAGTYPE_APE))
- || ((strcasecmp(name, "date") == 0) && (type == TAGTYPE_VORBIS)))
+ else if ((item == eYEAR && (type == TAGTYPE_APE))
+ || (item == eDATE && (type == TAGTYPE_VORBIS)))
{
/* Date's can be in any format in Vorbis. However most of them
* are in ISO8601 format so if we try and parse the first part
@@ -288,56 +323,43 @@ long parse_tag(const char* name, char* value, struct mp3entry* id3,
}
p = &(id3->year_string);
}
- else if (strcasecmp(name, "title") == 0)
+ else if (item == eTITLE)
{
p = &(id3->title);
}
- else if (strcasecmp(name, "artist") == 0)
+ else if (item == eARTIST)
{
p = &(id3->artist);
}
- else if (strcasecmp(name, "album") == 0)
+ else if (item == eALBUM)
{
p = &(id3->album);
}
- else if (strcasecmp(name, "genre") == 0)
+ else if (item == eGENRE)
{
p = &(id3->genre_string);
}
- else if (strcasecmp(name, "composer") == 0)
+ else if (item == eCOMPOSER)
{
p = &(id3->composer);
}
- else if (strcasecmp(name, "comment") == 0)
+ else if (item == eCOMMENT)
{
p = &(id3->comment);
}
- else if (strcasecmp(name, "albumartist") == 0)
+ else if (item == eALBUMARTIST || item == eALBUM_ARTIST)
{
p = &(id3->albumartist);
}
- else if (strcasecmp(name, "album artist") == 0)
+ else if (item == eENSEMBLE)
{
p = &(id3->albumartist);
}
- else if (strcasecmp(name, "ensemble") == 0)
- {
- p = &(id3->albumartist);
- }
- else if (strcasecmp(name, "grouping") == 0)
- {
- p = &(id3->grouping);
- }
- else if (strcasecmp(name, "content group") == 0)
- {
- p = &(id3->grouping);
- }
- else if (strcasecmp(name, "contentgroup") == 0)
+ else if (item == eGROUPING || item == eCONTENTGROUP || item == eCONTENT_GROUP)
{
p = &(id3->grouping);
}
- else if (strcasecmp(name, "musicbrainz_trackid") == 0
- || strcasecmp(name, "http://musicbrainz.org") == 0 )
+ else if (item == eMUSICBRAINZ1 || item == eMUSICBRAINZ2)
{
p = &(id3->mb_track_id);
}