mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-12 02:15:31 +00:00
gstobject: Replace recursive gst_object_has_ancestor() with an iterative version
This is slightly more efficient because the compiler can't do tail recursion here and has to keep all stack frames. Not that efficiency is that important here but I already had the iterative version somewhere else and both are easy to read.
This commit is contained in:
parent
4917bb4fc2
commit
b8454d623d
1 changed files with 12 additions and 9 deletions
|
@ -883,21 +883,24 @@ gst_object_unparent (GstObject * object)
|
|||
gboolean
|
||||
gst_object_has_ancestor (GstObject * object, GstObject * ancestor)
|
||||
{
|
||||
GstObject *parent;
|
||||
gboolean result = FALSE;
|
||||
GstObject *parent, *tmp;
|
||||
|
||||
if (object == NULL)
|
||||
if (!ancestor || !object)
|
||||
return FALSE;
|
||||
|
||||
if (object == ancestor)
|
||||
return TRUE;
|
||||
parent = gst_object_ref (object);
|
||||
do {
|
||||
if (parent == ancestor) {
|
||||
gst_object_unref (parent);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
parent = gst_object_get_parent (object);
|
||||
result = gst_object_has_ancestor (parent, ancestor);
|
||||
if (parent)
|
||||
tmp = gst_object_get_parent (parent);
|
||||
gst_object_unref (parent);
|
||||
parent = tmp;
|
||||
} while (parent);
|
||||
|
||||
return result;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue