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

Split FindObject into FindParent and FindChild

This avoids pushing and checking the mode parameter at each recursion.
Also, FindParent is now iterative.
parent c8631c65
...@@ -75,7 +75,8 @@ ...@@ -75,7 +75,8 @@
static int DumpCommand( vlc_object_t *, char const *, static int DumpCommand( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
static vlc_object_t * FindObject ( vlc_object_t *, int, int ); static vlc_object_t * FindParent ( vlc_object_t *, int );
static vlc_object_t * FindChild ( vlc_object_t *, int );
static vlc_object_t * FindObjectName( vlc_object_t *, const char *, int ); static vlc_object_t * FindObjectName( vlc_object_t *, const char *, int );
static void PrintObject ( vlc_object_t *, const char * ); static void PrintObject ( vlc_object_t *, const char * );
static void DumpStructure ( vlc_object_t *, int, char * ); static void DumpStructure ( vlc_object_t *, int, char * );
...@@ -466,7 +467,17 @@ void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode ) ...@@ -466,7 +467,17 @@ void * __vlc_object_find( vlc_object_t *p_this, int i_type, int i_mode )
} }
libvlc_lock (p_this->p_libvlc); libvlc_lock (p_this->p_libvlc);
p_found = FindObject( p_this, i_type, i_mode ); switch (i_mode)
{
case FIND_PARENT:
p_found = FindParent (p_this, i_type);
break;
case FIND_CHILD:
p_found = FindChild (p_this, i_type);
break;
default:
assert (0);
}
libvlc_unlock (p_this->p_libvlc); libvlc_unlock (p_this->p_libvlc);
return p_found; return p_found;
} }
...@@ -920,57 +931,34 @@ void vlc_list_release( vlc_list_t *p_list ) ...@@ -920,57 +931,34 @@ void vlc_list_release( vlc_list_t *p_list )
/* Following functions are local */ /* Following functions are local */
static vlc_object_t * FindObject( vlc_object_t *p_this, int i_type, int i_mode ) static vlc_object_t *FindParent (vlc_object_t *p_this, int i_type)
{ {
int i; for (vlc_object_t *parent = p_this->p_parent;
vlc_object_t *p_tmp; parent != NULL;
parent = parent->p_parent)
switch( i_mode )
{ {
case FIND_PARENT: if (vlc_internals (parent)->i_object_type == i_type)
p_tmp = p_this->p_parent; return vlc_object_hold (parent);
if( p_tmp )
{
if( vlc_internals( p_tmp )->i_object_type == i_type )
{
vlc_object_hold( p_tmp );
return p_tmp;
} }
else return NULL;
{ }
return FindObject( p_tmp, i_type, i_mode );
}
}
break;
case FIND_CHILD: static vlc_object_t *FindChild (vlc_object_t *p_this, int i_type)
for( i = vlc_internals( p_this )->i_children; i--; ) {
{ for (int i = vlc_internals( p_this )->i_children; i--; )
p_tmp = vlc_internals( p_this )->pp_children[i];
if( vlc_internals( p_tmp )->i_object_type == i_type )
{
vlc_object_hold( p_tmp );
return p_tmp;
}
else if( vlc_internals( p_tmp )->i_children )
{
p_tmp = FindObject( p_tmp, i_type, i_mode );
if( p_tmp )
{ {
return p_tmp; vlc_object_t *child = vlc_internals (p_this)->pp_children[i];
} if (vlc_internals (child)->i_object_type == i_type)
} return vlc_object_hold (child);
}
break;
case FIND_ANYWHERE: child = FindChild (child, i_type);
/* Handled in vlc_object_find */ if (child != NULL)
break; return child;
} }
return NULL; return NULL;
} }
static vlc_object_t * FindObjectName( vlc_object_t *p_this, static vlc_object_t * FindObjectName( vlc_object_t *p_this,
const char *psz_name, const char *psz_name,
int i_mode ) int i_mode )
......
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