[vlc-devel] commit: Split FindObject into FindParent and FindChild ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sat Jan 23 12:41:12 CET 2010
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jan 23 13:30:49 2010 +0200| [5d600458c9451357e63dd446199e05fd68deb33a] | committer: 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.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5d600458c9451357e63dd446199e05fd68deb33a
---
src/misc/objects.c | 78 ++++++++++++++++++++++------------------------------
1 files changed, 33 insertions(+), 45 deletions(-)
diff --git a/src/misc/objects.c b/src/misc/objects.c
index ab3cec3..e6110e4 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -75,7 +75,8 @@
static int DumpCommand( vlc_object_t *, char const *,
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 void PrintObject ( vlc_object_t *, const 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 )
}
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);
return p_found;
}
@@ -920,57 +931,34 @@ void vlc_list_release( vlc_list_t *p_list )
/* 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;
- vlc_object_t *p_tmp;
-
- switch( i_mode )
+ for (vlc_object_t *parent = p_this->p_parent;
+ parent != NULL;
+ parent = parent->p_parent)
{
- case FIND_PARENT:
- p_tmp = p_this->p_parent;
- if( p_tmp )
- {
- if( vlc_internals( p_tmp )->i_object_type == i_type )
- {
- vlc_object_hold( p_tmp );
- return p_tmp;
- }
- else
- {
- return FindObject( p_tmp, i_type, i_mode );
- }
- }
- break;
+ if (vlc_internals (parent)->i_object_type == i_type)
+ return vlc_object_hold (parent);
+ }
+ return NULL;
+}
- case FIND_CHILD:
- for( 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;
- }
- }
- }
- break;
+static vlc_object_t *FindChild (vlc_object_t *p_this, int i_type)
+{
+ for (int i = vlc_internals( p_this )->i_children; i--; )
+ {
+ 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);
- case FIND_ANYWHERE:
- /* Handled in vlc_object_find */
- break;
+ child = FindChild (child, i_type);
+ if (child != NULL)
+ return child;
}
-
return NULL;
}
+
static vlc_object_t * FindObjectName( vlc_object_t *p_this,
const char *psz_name,
int i_mode )
More information about the vlc-devel
mailing list