tag: id3v2: avoid some relocations, make table static
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 14 Aug 2011 12:32:12 +0000 (13:32 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 14 Aug 2011 23:10:34 +0000 (00:10 +0100)
gst-libs/gst/tag/id3v2.c

index a8bcdba..6dabddd 100644 (file)
@@ -265,16 +265,15 @@ id3v2_frame_hdr_size (guint id3v2ver)
   }
 }
 
-static const gchar *obsolete_frame_ids[] = {
-  "CRM", "EQU", "LNK", "RVA", "TIM", "TSI",     /* From 2.2 */
-  "EQUA", "RVAD", "TIME", "TRDA", "TSIZ",       /* From 2.3 */
-  NULL
+static const gchar obsolete_frame_ids[][5] = {
+  {"CRM"}, {"EQU"}, {"LNK"}, {"RVA"}, {"TIM"}, {"TSI"}, /* From 2.2 */
+  {"EQUA"}, {"RVAD"}, {"TIME"}, {"TRDA"}, {"TSIZ"}      /* From 2.3 */
 };
 
-const struct ID3v2FrameIDConvert
+static const struct ID3v2FrameIDConvert
 {
-  const gchar *orig;
-  const gchar *new;
+  const gchar orig[5];
+  const gchar new[5];
 } frame_id_conversions[] = {
   /* 2.3.x frames */
   {
@@ -338,28 +337,24 @@ const struct ID3v2FrameIDConvert
   "WCM", "WCOM"}, {
   "WCP", "WCOP"}, {
   "WPB", "WPUB"}, {
-  "WXX", "WXXX"}, {
-  NULL, NULL}
+  "WXX", "WXXX"}
 };
 
 static gboolean
 convert_fid_to_v240 (gchar * frame_id)
 {
-  gint i = 0;
+  gint i;
 
-  while (obsolete_frame_ids[i] != NULL) {
+  for (i = 0; i < G_N_ELEMENTS (obsolete_frame_ids); ++i) {
     if (strncmp (frame_id, obsolete_frame_ids[i], 5) == 0)
       return TRUE;
-    i++;
   }
 
-  i = 0;
-  while (frame_id_conversions[i].orig != NULL) {
+  for (i = 0; i < G_N_ELEMENTS (frame_id_conversions); ++i) {
     if (strncmp (frame_id, frame_id_conversions[i].orig, 5) == 0) {
       strcpy (frame_id, frame_id_conversions[i].new);
       return FALSE;
     }
-    i++;
   }
   return FALSE;
 }