[gst-cvs] gstreamer: gstobject: Replace recursive gst_object_has_ancestor() with an iterative version
Sebastian Dröge
slomo at kemper.freedesktop.org
Tue Oct 13 23:34:20 PDT 2009
Module: gstreamer
Branch: master
Commit: b8454d623d4d92949a0548b8d1d6bc061e18b11b
URL: http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=b8454d623d4d92949a0548b8d1d6bc061e18b11b
Author: Sebastian Dröge <sebastian.droege at collabora.co.uk>
Date: Wed Oct 14 08:30:07 2009 +0200
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.
---
gst/gstobject.c | 21 ++++++++++++---------
1 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/gst/gstobject.c b/gst/gstobject.c
index 1a679db..1448341 100644
--- a/gst/gstobject.c
+++ b/gst/gstobject.c
@@ -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;
}
/**
More information about the Gstreamer-commits
mailing list