[vlc-devel] commit: FindObjectName: split parent and child search modes ( 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:40:51 2010 +0200| [af3779ff1c972dc76b58c6072fef3cff0d68c911] | committer: Rémi Denis-Courmont 

FindObjectName: split parent and child search modes

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=af3779ff1c972dc76b58c6072fef3cff0d68c911
---

 src/misc/objects.c |   86 ++++++++++++++++++++--------------------------------
 1 files changed, 33 insertions(+), 53 deletions(-)

diff --git a/src/misc/objects.c b/src/misc/objects.c
index fa28541..2b6ed7d 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -77,7 +77,8 @@ static int  DumpCommand( vlc_object_t *, char const *,
 
 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 * FindParentName( vlc_object_t *, const char * );
+static vlc_object_t * FindChildName ( vlc_object_t *, const char * );
 static void           PrintObject   ( vlc_object_t *, const char * );
 static void           DumpStructure ( vlc_object_t *, int, char * );
 
@@ -532,10 +533,17 @@ vlc_object_t *vlc_object_find_name( vlc_object_t *p_this,
                                      FIND_CHILD);
 
     libvlc_lock (p_this->p_libvlc);
-
-    /* Otherwise, recursively look for the object */
-    p_found = FindObjectName( p_this, psz_name, i_mode );
-
+    switch (i_mode)
+    {
+        case FIND_PARENT:
+            p_found = FindParentName (p_this, psz_name);
+            break;
+        case FIND_CHILD:
+            p_found = FindChildName (p_this, psz_name);
+            break;
+        default:
+            assert (0);
+    }
     libvlc_unlock (p_this->p_libvlc);
     return p_found;
 }
@@ -927,6 +935,18 @@ static vlc_object_t *FindParent (vlc_object_t *p_this, int i_type)
     return NULL;
 }
 
+static vlc_object_t *FindParentName (vlc_object_t *p_this, const char *name)
+{
+    for (vlc_object_t *parent = p_this->p_parent;
+         parent != NULL;
+         parent = parent->p_parent)
+    {
+        if (!objnamecmp (parent, name))
+            return vlc_object_hold (parent);
+    }
+    return NULL;
+}
+
 static vlc_object_t *FindChild (vlc_object_t *p_this, int i_type)
 {
     for (int i = vlc_internals( p_this )->i_children; i--; )
@@ -942,61 +962,21 @@ static vlc_object_t *FindChild (vlc_object_t *p_this, int i_type)
     return NULL;
 }
 
-
-static vlc_object_t * FindObjectName( vlc_object_t *p_this,
-                                      const char *psz_name,
-                                      int i_mode )
+static vlc_object_t *FindChildName (vlc_object_t *p_this, const char *name)
 {
-    int i;
-    vlc_object_t *p_tmp;
-
-    switch( i_mode )
+    for (int i = vlc_internals( p_this )->i_children; i--; )
     {
-    case FIND_PARENT:
-        p_tmp = p_this->p_parent;
-        if( p_tmp )
-        {
-            if( !objnamecmp(p_tmp, psz_name) )
-            {
-                vlc_object_hold( p_tmp );
-                return p_tmp;
-            }
-            else
-            {
-                return FindObjectName( p_tmp, psz_name, i_mode );
-            }
-        }
-        break;
-
-    case FIND_CHILD:
-        for( i = vlc_internals( p_this )->i_children; i--; )
-        {
-            p_tmp = vlc_internals( p_this )->pp_children[i];
-            if( !objnamecmp(p_tmp, psz_name ) )
-            {
-                vlc_object_hold( p_tmp );
-                return p_tmp;
-            }
-            else if( vlc_internals( p_tmp )->i_children )
-            {
-                p_tmp = FindObjectName( p_tmp, psz_name, i_mode );
-                if( p_tmp )
-                {
-                    return p_tmp;
-                }
-            }
-        }
-        break;
+        vlc_object_t *child = vlc_internals (p_this)->pp_children[i];
+        if (!objnamecmp (child, name))
+            return vlc_object_hold (child);
 
-    case FIND_ANYWHERE:
-        /* Handled in vlc_object_find */
-        break;
+        child = FindChildName (child, name);
+        if (child != NULL)
+            return child;
     }
-
     return NULL;
 }
 
-
 static void PrintObject( vlc_object_t *p_this, const char *psz_prefix )
 {
     char psz_children[20], psz_refcount[20], psz_thread[30], psz_name[50],




More information about the vlc-devel mailing list