Commit b893d33d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

variables: store a single type per list

All entries in a single list always have the same type anyway.
parent 21938b73
...@@ -362,10 +362,9 @@ typedef union ...@@ -362,10 +362,9 @@ typedef union
*/ */
struct vlc_list_t struct vlc_list_t
{ {
int i_count; int i_type;
vlc_value_t * p_values; int i_count;
int * pi_types; vlc_value_t *p_values;
}; };
/***************************************************************************** /*****************************************************************************
......
...@@ -85,8 +85,7 @@ static int vlclua_pushlist( lua_State *L, vlc_list_t *p_list ) ...@@ -85,8 +85,7 @@ static int vlclua_pushlist( lua_State *L, vlc_list_t *p_list )
for( int i = 0; i < i_count; i++ ) for( int i = 0; i < i_count; i++ )
{ {
lua_pushinteger( L, i+1 ); lua_pushinteger( L, i+1 );
if( !vlclua_pushvalue( L, p_list->pi_types[i], if( !vlclua_pushvalue( L, p_list->i_type, p_list->p_values[i], true ) )
p_list->p_values[i], true ) )
lua_pushnil( L ); lua_pushnil( L );
lua_settable( L, -3 ); lua_settable( L, -3 );
} }
......
...@@ -103,7 +103,7 @@ static void FreeList( vlc_value_t *p_val ) ...@@ -103,7 +103,7 @@ static void FreeList( vlc_value_t *p_val )
int i; int i;
for( i = 0; i < p_val->p_list->i_count; i++ ) for( i = 0; i < p_val->p_list->i_count; i++ )
{ {
switch( p_val->p_list->pi_types[i] & VLC_VAR_CLASS ) switch( p_val->p_list->i_type & VLC_VAR_CLASS )
{ {
case VLC_VAR_STRING: case VLC_VAR_STRING:
FreeString( &p_val->p_list->p_values[i] ); FreeString( &p_val->p_list->p_values[i] );
...@@ -114,10 +114,7 @@ static void FreeList( vlc_value_t *p_val ) ...@@ -114,10 +114,7 @@ static void FreeList( vlc_value_t *p_val )
} }
if( p_val->p_list->i_count ) if( p_val->p_list->i_count )
{
free( p_val->p_list->p_values ); free( p_val->p_list->p_values );
free( p_val->p_list->pi_types );
}
free( p_val->p_list ); free( p_val->p_list );
} }
...@@ -561,29 +558,28 @@ int var_Change( vlc_object_t *p_this, const char *psz_name, ...@@ -561,29 +558,28 @@ int var_Change( vlc_object_t *p_this, const char *psz_name,
{ {
p_val->p_list->p_values = malloc( p_var->choices.i_count p_val->p_list->p_values = malloc( p_var->choices.i_count
* sizeof(vlc_value_t) ); * sizeof(vlc_value_t) );
p_val->p_list->pi_types = malloc( p_var->choices.i_count
* sizeof(int) );
if( p_val2 ) if( p_val2 )
{ {
p_val2->p_list->p_values = p_val2->p_list->p_values =
malloc( p_var->choices.i_count * sizeof(vlc_value_t) ); malloc( p_var->choices.i_count * sizeof(vlc_value_t) );
p_val2->p_list->pi_types =
malloc( p_var->choices.i_count * sizeof(int) );
} }
} }
p_val->p_list->i_type = p_var->i_type;
p_val->p_list->i_count = p_var->choices.i_count; p_val->p_list->i_count = p_var->choices.i_count;
if( p_val2 ) p_val2->p_list->i_count = p_var->choices.i_count; if( p_val2 )
{
p_val2->p_list->i_type = VLC_VAR_STRING;
p_val2->p_list->i_count = p_var->choices.i_count;
}
for( int i = 0 ; i < p_var->choices.i_count ; i++ ) for( int i = 0 ; i < p_var->choices.i_count ; i++ )
{ {
p_val->p_list->p_values[i] = p_var->choices.p_values[i]; p_val->p_list->p_values[i] = p_var->choices.p_values[i];
p_val->p_list->pi_types[i] = p_var->i_type;
p_var->ops->pf_dup( &p_val->p_list->p_values[i] ); p_var->ops->pf_dup( &p_val->p_list->p_values[i] );
if( p_val2 ) if( p_val2 )
{ {
p_val2->p_list->p_values[i].psz_string = p_val2->p_list->p_values[i].psz_string =
p_var->choices_text.p_values[i].psz_string ? p_var->choices_text.p_values[i].psz_string ?
strdup(p_var->choices_text.p_values[i].psz_string) : NULL; strdup(p_var->choices_text.p_values[i].psz_string) : NULL;
p_val2->p_list->pi_types[i] = VLC_VAR_STRING;
} }
} }
break; break;
...@@ -1445,10 +1441,7 @@ void var_FreeList( vlc_value_t *p_val, vlc_value_t *p_val2 ) ...@@ -1445,10 +1441,7 @@ void var_FreeList( vlc_value_t *p_val, vlc_value_t *p_val2 )
for( int i = 0; i < p_val2->p_list->i_count; i++ ) for( int i = 0; i < p_val2->p_list->i_count; i++ )
free( p_val2->p_list->p_values[i].psz_string ); free( p_val2->p_list->p_values[i].psz_string );
if( p_val2->p_list->i_count ) if( p_val2->p_list->i_count )
{
free( p_val2->p_list->p_values ); free( p_val2->p_list->p_values );
free( p_val2->p_list->pi_types );
}
free( p_val2->p_list ); free( p_val2->p_list );
} }
} }
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