[vlc-devel] [PATCH] core/input/item: clean-up GuessType

Filip Roséen filip at videolabs.io
Fri May 13 19:23:10 CEST 2016


There is no need for struct item_type_entry to be in the global scope,
and given that the standard guarantees that the first member of a struct
will reside at the address of the struct itself we do not need "typecmp"
to have access to the "real" type.

Instead we can simply convert the pointer-to-void to
pointer-to-const-char, and continue as normal.
---
 src/input/item.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/input/item.c b/src/input/item.c
index 0dfb820..5307a37 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -1006,17 +1006,10 @@ input_item_t *input_item_Copy( input_item_t *p_input )
     return item;
 }
 
-struct item_type_entry
-{
-    const char psz_scheme[7];
-    uint8_t    i_type;
-    bool       b_net;
-};
-
 static int typecmp( const void *key, const void *entry )
 {
-    const struct item_type_entry *type = entry;
-    const char *uri = key, *scheme = type->psz_scheme;
+    const char * scheme = entry;
+    const char * uri = key;
 
     return strncmp( uri, scheme, strlen( scheme ) );
 }
@@ -1024,8 +1017,12 @@ static int typecmp( const void *key, const void *entry )
 /* Guess the type of the item using the beginning of the mrl */
 static int GuessType( const input_item_t *p_item, bool *p_net )
 {
-    static const struct item_type_entry tab[] =
-    {   /* /!\ Alphabetical order /!\ */
+    static const struct item_type_entry {
+        const char * psz_scheme;
+        uint8_t      i_type;
+        bool         b_net;
+    } tab[] = {
+        /* /!\ Alphabetical order /!\ */
         /* Short match work, not just exact match */
         { "alsa",   ITEM_TYPE_CARD, false },
         { "atsc",   ITEM_TYPE_CARD, false },
-- 
2.8.2



More information about the vlc-devel mailing list