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

Allocate each object variable separately

This reduces the amount of memory copied when creating/deleting a
variable on an object. We now use a table of pointers instead of table
of variable_t.

This also simplifies callback handling a bit as the variable_t cannot
move anymore while we wait. Earlier another thread could add or remove
another variable on the same object, thus changing the variable table.

With this change, we could also store non-serialized data (i.e.
non-movable with memcpy/memmove) directly inside variable_t.
parent 8e3df82b
......@@ -162,7 +162,7 @@ typedef struct vlc_object_internals_t
char *psz_name; /* given name */
/* Object variables */
variable_t * p_vars;
variable_t **pp_vars;
vlc_mutex_t var_lock;
vlc_cond_t var_wait;
int i_vars;
......
......@@ -131,13 +131,7 @@ void *__vlc_custom_create( vlc_object_t *p_this, size_t i_size,
p_new->i_flags = p_this->i_flags
& (OBJECT_FLAGS_NODBG|OBJECT_FLAGS_QUIET|OBJECT_FLAGS_NOINTERACT);
p_priv->p_vars = calloc( 16, sizeof( variable_t ) );
if( !p_priv->p_vars )
{
free( p_priv );
return NULL;
}
p_priv->pp_vars = NULL;
if( p_this == NULL )
{
......@@ -291,10 +285,9 @@ static void vlc_object_destroy( vlc_object_t *p_this )
* no memmove calls have to be done. */
while( p_priv->i_vars )
{
var_Destroy( p_this, p_priv->p_vars[p_priv->i_vars - 1].psz_name );
var_Destroy( p_this, p_priv->pp_vars[p_priv->i_vars - 1]->psz_name );
}
free( p_priv->p_vars );
vlc_cond_destroy( &p_priv->var_wait );
vlc_mutex_destroy( &p_priv->var_lock );
......@@ -822,7 +815,7 @@ static int DumpCommand( vlc_object_t *p_this, char const *psz_cmd,
printf( " `-o No variables\n" );
for( i = 0; i < vlc_internals( p_object )->i_vars; i++ )
{
variable_t *p_var = vlc_internals( p_object )->p_vars + i;
const variable_t *p_var = vlc_internals( p_object )->pp_vars[i];
const char *psz_type = "unknown";
switch( p_var->i_type & VLC_VAR_TYPE )
......
This diff is collapsed.
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