mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
gst/: Use PyList_SetItem() instead of PyList_Append() for faster list creation and proper python refcounting.
Original commit message from CVS: Reviewed by Edward Hervey <edward@fluendo.com> * gst/gst.override: * gst/gstevent.override: * gst/gstpad.override: * gst/gstquery.override: Use PyList_SetItem() instead of PyList_Append() for faster list creation and proper python refcounting. Closes bug #318684
This commit is contained in:
parent
a31f5476e8
commit
e3ac835751
5 changed files with 108 additions and 92 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2005-10-13 Alessandro Decina <alessandro@nnva.org>
|
||||
|
||||
Reviewed by Edward Hervey <edward@fluendo.com>
|
||||
|
||||
* gst/gst.override:
|
||||
* gst/gstevent.override:
|
||||
* gst/gstpad.override:
|
||||
* gst/gstquery.override:
|
||||
Use PyList_SetItem() instead of PyList_Append() for faster list creation
|
||||
and proper python refcounting.
|
||||
Closes bug #318684
|
||||
|
||||
2005-10-13 Alessandro Decina <alessandro@nnva.org>
|
||||
|
||||
Reviewed by Edward Hervey <edward@fluendo.com>
|
||||
|
|
|
@ -388,15 +388,16 @@ _wrap_gst_registry_get_path_list (PyGObject *self)
|
|||
GstRegistry *registry;
|
||||
GList *l, *paths;
|
||||
PyObject *list;
|
||||
gint i;
|
||||
|
||||
registry = GST_REGISTRY (self->obj);
|
||||
|
||||
paths = gst_registry_get_path_list (registry);
|
||||
|
||||
list = PyList_New (0);
|
||||
for (l = paths; l; l = l->next) {
|
||||
list = PyList_New (g_list_length(paths));
|
||||
for (l = paths, i = 0; l; l = l->next, ++i) {
|
||||
gchar *path = (gchar *) l->data;
|
||||
PyList_Append (list, PyString_FromString(path));
|
||||
PyList_SetItem (list, i, PyString_FromString(path));
|
||||
}
|
||||
g_list_free (paths);
|
||||
|
||||
|
@ -411,15 +412,16 @@ _wrap_gst_registry_get_plugin_list (PyGObject *self)
|
|||
GstRegistry *registry;
|
||||
GList *l, *plugins;
|
||||
PyObject *list;
|
||||
|
||||
gint i;
|
||||
|
||||
registry = GST_REGISTRY (self->obj);
|
||||
|
||||
plugins = gst_registry_get_plugin_list (registry);
|
||||
|
||||
list = PyList_New (0);
|
||||
for (l = plugins; l; l = l->next) {
|
||||
list = PyList_New (g_list_length(plugins));
|
||||
for (l = plugins, i = 0; l; l = l->next, ++i) {
|
||||
GstPlugin *plugin = (GstPlugin *) l->data;
|
||||
PyList_Append (list, pygobject_new (G_OBJECT (plugin)));
|
||||
PyList_SetItem (list, i, pygobject_new (G_OBJECT (plugin)));
|
||||
}
|
||||
g_list_free (plugins);
|
||||
|
||||
|
@ -438,6 +440,7 @@ _wrap_gst_registry_get_feature_list (PyGObject *self, PyObject *args, PyObject *
|
|||
GstRegistry *registry;
|
||||
GList *l, *features;
|
||||
PyObject *list;
|
||||
gint i;
|
||||
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
||||
|
@ -450,10 +453,10 @@ _wrap_gst_registry_get_feature_list (PyGObject *self, PyObject *args, PyObject *
|
|||
|
||||
features = gst_registry_get_feature_list (registry, type);
|
||||
|
||||
list = PyList_New (0);
|
||||
for (l = features; l; l = l->next) {
|
||||
list = PyList_New (g_list_length(features));
|
||||
for (l = features, i = 0; l; l = l->next, ++i) {
|
||||
GstPluginFeature *feature = (GstPluginFeature *) l->data;
|
||||
PyList_Append (list, pygobject_new (G_OBJECT (feature)));
|
||||
PyList_SetItem (list, i, pygobject_new (G_OBJECT (feature)));
|
||||
}
|
||||
g_list_free (features);
|
||||
|
||||
|
@ -471,7 +474,7 @@ _wrap_gst_registry_get_feature_list_by_plugin (PyGObject *self, PyObject *args,
|
|||
GstRegistry *registry;
|
||||
GList *l, *features;
|
||||
PyObject *list;
|
||||
|
||||
gint i;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
||||
"s:GstRegistry.get_feature_list_by_plugin", kwlist, &name))
|
||||
|
@ -481,10 +484,10 @@ _wrap_gst_registry_get_feature_list_by_plugin (PyGObject *self, PyObject *args,
|
|||
|
||||
features = gst_registry_get_feature_list_by_plugin (registry, name);
|
||||
|
||||
list = PyList_New (0);
|
||||
for (l = features; l; l = l->next) {
|
||||
list = PyList_New (g_list_length(features));
|
||||
for (l = features, i = 0; l; l = l->next, ++i) {
|
||||
GstPluginFeature *feature = (GstPluginFeature *) l->data;
|
||||
PyList_Append (list, pygobject_new (G_OBJECT (feature)));
|
||||
PyList_SetItem (list, i, pygobject_new (G_OBJECT (feature)));
|
||||
}
|
||||
g_list_free (features);
|
||||
|
||||
|
@ -539,15 +542,14 @@ _wrap_gst_xml_get_topelements(PyGObject *self)
|
|||
{
|
||||
GList *l, *xml_elements;
|
||||
PyObject *py_list;
|
||||
|
||||
py_list = PyList_New(0);
|
||||
gint i;
|
||||
|
||||
xml_elements = gst_xml_get_topelements(GST_XML(self->obj));
|
||||
for (l = xml_elements; l; l = l->next) {
|
||||
GstElement *element = (GstElement*)l->data;
|
||||
|
||||
PyList_Append(py_list, pygstobject_new(G_OBJECT(element)));
|
||||
gst_object_unref (element);
|
||||
py_list = PyList_New(g_list_length(xml_elements));
|
||||
for (l = xml_elements, i = 0; l; l = l->next, ++i) {
|
||||
GstElement *element = (GstElement*)l->data;
|
||||
PyList_SetItem(py_list, i, pygstobject_new(G_OBJECT(element)));
|
||||
gst_object_unref (element);
|
||||
}
|
||||
|
||||
return py_list;
|
||||
|
@ -660,11 +662,11 @@ _wrap_gst_uri_handler_get_protocols (PyGObject *self)
|
|||
Py_INCREF (Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
ret = PyList_New(0);
|
||||
|
||||
|
||||
len = g_strv_length (tab);
|
||||
ret = PyList_New(len);
|
||||
for (i = 0; i < len; i++) {
|
||||
PyList_Append(ret, PyString_FromString(tab[i]));
|
||||
PyList_SetItem(ret, i, PyString_FromString(tab[i]));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -68,13 +68,13 @@ _wrap_gst_event_parse_newsegment (PyGstMiniObject *self)
|
|||
gst_event_parse_newsegment (GST_EVENT(self->obj), &update, &rate, &format,
|
||||
&start_value, &stop_value, &base);
|
||||
|
||||
ret = PyList_New (0);
|
||||
PyList_Append (ret, PyBool_FromLong(update));
|
||||
PyList_Append (ret, PyFloat_FromDouble(rate));
|
||||
PyList_Append (ret, pyg_enum_from_gtype (GST_TYPE_FORMAT, format));
|
||||
PyList_Append (ret, PyLong_FromUnsignedLongLong(start_value));
|
||||
PyList_Append (ret, PyLong_FromUnsignedLongLong(stop_value));
|
||||
PyList_Append (ret, PyLong_FromUnsignedLongLong(base));
|
||||
ret = PyList_New (6);
|
||||
PyList_SetItem (ret, 0, PyBool_FromLong(update));
|
||||
PyList_SetItem (ret, 1, PyFloat_FromDouble(rate));
|
||||
PyList_SetItem (ret, 2, pyg_enum_from_gtype (GST_TYPE_FORMAT, format));
|
||||
PyList_SetItem (ret, 3, PyLong_FromUnsignedLongLong(start_value));
|
||||
PyList_SetItem (ret, 4, PyLong_FromUnsignedLongLong(stop_value));
|
||||
PyList_SetItem (ret, 5, PyLong_FromUnsignedLongLong(base));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -115,10 +115,10 @@ _wrap_gst_event_parse_qos (PyGstMiniObject *self)
|
|||
gst_event_parse_qos (GST_EVENT(self->obj), &proportion,
|
||||
&diff, ×tamp);
|
||||
|
||||
ret = PyList_New (0);
|
||||
PyList_Append (ret, PyFloat_FromDouble(proportion));
|
||||
PyList_Append (ret, PyLong_FromLongLong(diff));
|
||||
PyList_Append (ret, PyLong_FromUnsignedLongLong(timestamp));
|
||||
ret = PyList_New (3);
|
||||
PyList_SetItem (ret, 0, PyFloat_FromDouble(proportion));
|
||||
PyList_SetItem (ret, 1, PyLong_FromLongLong(diff));
|
||||
PyList_SetItem (ret, 2, PyLong_FromUnsignedLongLong(timestamp));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -144,14 +144,15 @@ _wrap_gst_event_parse_seek (PyGstMiniObject *self)
|
|||
gst_event_parse_seek (GST_EVENT(self->obj), &rate, &format, &flags,
|
||||
&cur_type, &cur, &stop_type, &stop);
|
||||
|
||||
ret = PyList_New (0);
|
||||
PyList_Append (ret, PyFloat_FromDouble(rate));
|
||||
PyList_Append (ret, pyg_enum_from_gtype (GST_TYPE_FORMAT, format));
|
||||
PyList_Append (ret, pyg_flags_from_gtype (GST_TYPE_SEEK_FLAGS, flags));
|
||||
PyList_Append (ret, pyg_enum_from_gtype (GST_TYPE_SEEK_TYPE, cur_type));
|
||||
PyList_Append (ret, PyLong_FromUnsignedLongLong (cur));
|
||||
PyList_Append (ret, pyg_enum_from_gtype (GST_TYPE_SEEK_TYPE, stop_type));
|
||||
PyList_Append (ret, PyLong_FromUnsignedLongLong (stop));
|
||||
ret = PyList_New (7);
|
||||
PyList_SetItem (ret, 0, PyFloat_FromDouble(rate));
|
||||
PyList_SetItem (ret, 1, pyg_enum_from_gtype (GST_TYPE_FORMAT, format));
|
||||
PyList_SetItem (ret, 2, pyg_flags_from_gtype (GST_TYPE_SEEK_FLAGS, flags));
|
||||
PyList_SetItem (ret, 3, pyg_enum_from_gtype (GST_TYPE_SEEK_TYPE, cur_type));
|
||||
PyList_SetItem (ret, 4, PyLong_FromUnsignedLongLong (cur));
|
||||
PyList_SetItem (ret, 5,
|
||||
pyg_enum_from_gtype (GST_TYPE_SEEK_TYPE, stop_type));
|
||||
PyList_SetItem (ret, 6, PyLong_FromUnsignedLongLong (stop));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -674,14 +674,14 @@ _wrap_gst_pad_query_position (PyGObject *self, PyObject *args)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
ret = PyList_New(0);
|
||||
if ((gst_pad_query_position(GST_PAD (self->obj), (GstFormat*) &format, &cur, &end))) {
|
||||
PyList_Append(ret, PyLong_FromLongLong(cur));
|
||||
PyList_Append(ret, PyLong_FromLongLong(end));
|
||||
PyList_Append(ret, pyg_enum_from_gtype (GST_TYPE_FORMAT, format ));
|
||||
ret = PyList_New(3);
|
||||
PyList_SetItem(ret, 0, PyLong_FromLongLong(cur));
|
||||
PyList_SetItem(ret, 1, PyLong_FromLongLong(end));
|
||||
PyList_SetItem(ret, 2, pyg_enum_from_gtype (GST_TYPE_FORMAT, format ));
|
||||
} else {
|
||||
Py_INCREF(Py_None);
|
||||
ret = Py_None;
|
||||
Py_INCREF(Py_None);
|
||||
ret = Py_None;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -720,9 +720,9 @@ _wrap_gst_pad_query_convert (PyGObject *self, PyObject *args, PyObject *kwargs)
|
|||
return Py_None;
|
||||
}
|
||||
|
||||
ret = PyList_New(0);
|
||||
PyList_Append(ret, pyg_enum_from_gtype (GST_TYPE_FORMAT, destformat));
|
||||
PyList_Append(ret, PyLong_FromLongLong(dstval));
|
||||
ret = PyList_New(2);
|
||||
PyList_SetItem(ret, 0, pyg_enum_from_gtype (GST_TYPE_FORMAT, destformat));
|
||||
PyList_SetItem(ret, 1, PyLong_FromLongLong(dstval));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -747,13 +747,12 @@ _wrap_gst_pad_alloc_buffer (PyGObject *self, PyObject * args, PyObject *kwargs)
|
|||
caps = pyg_boxed_get(pcaps, GstCaps);
|
||||
res = gst_pad_alloc_buffer (GST_PAD(pygobject_get(self)),
|
||||
offset, size, caps, &buf);
|
||||
ret = PyList_New(0);
|
||||
PyList_Append(ret, pyg_enum_from_gtype(GST_TYPE_FLOW_RETURN, res));
|
||||
ret = PyList_New(2);
|
||||
PyList_SetItem(ret, 0, pyg_enum_from_gtype(GST_TYPE_FLOW_RETURN, res));
|
||||
if (res != GST_FLOW_OK) {
|
||||
Py_INCREF(Py_None);
|
||||
PyList_Append(ret, Py_None);
|
||||
PyList_Append(ret, Py_None);
|
||||
} else {
|
||||
PyList_Append(ret, pygstminiobject_new(GST_MINI_OBJECT(buf)));
|
||||
PyList_SetItem(ret, 1, pygstminiobject_new(GST_MINI_OBJECT(buf)));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -775,13 +774,12 @@ _wrap_gst_pad_pull_range (PyGObject *self, PyObject * args, PyObject *kwargs)
|
|||
return NULL;
|
||||
res = gst_pad_pull_range (GST_PAD(pygobject_get(self)),
|
||||
offset, size, &buf);
|
||||
ret = PyList_New(0);
|
||||
PyList_Append(ret, pyg_enum_from_gtype(GST_TYPE_FLOW_RETURN, res));
|
||||
ret = PyList_New(2);
|
||||
PyList_SetItem(ret, 0, pyg_enum_from_gtype(GST_TYPE_FLOW_RETURN, res));
|
||||
if (res != GST_FLOW_OK) {
|
||||
Py_INCREF(Py_None);
|
||||
PyList_Append(ret, Py_None);
|
||||
PyList_Append(ret, Py_None);
|
||||
} else {
|
||||
PyList_Append(ret, pygstminiobject_new(GST_MINI_OBJECT(buf)));
|
||||
PyList_SetItem(ret, 1, pygstminiobject_new(GST_MINI_OBJECT(buf)));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -803,13 +801,12 @@ _wrap_gst_pad_get_range (PyGObject *self, PyObject * args, PyObject *kwargs)
|
|||
return NULL;
|
||||
res = gst_pad_get_range (GST_PAD(pygobject_get(self)),
|
||||
offset, size, &buf);
|
||||
ret = PyList_New(0);
|
||||
PyList_Append(ret, pyg_enum_from_gtype(GST_TYPE_FLOW_RETURN, res));
|
||||
ret = PyList_New(2);
|
||||
PyList_SetItem(ret, 0, pyg_enum_from_gtype(GST_TYPE_FLOW_RETURN, res));
|
||||
if (res != GST_FLOW_OK) {
|
||||
Py_INCREF(Py_None);
|
||||
PyList_Append(ret, Py_None);
|
||||
PyList_Append(ret, Py_None);
|
||||
} else {
|
||||
PyList_Append(ret, pygstminiobject_new(GST_MINI_OBJECT(buf)));
|
||||
PyList_SetItem(ret, 1, pygstminiobject_new(GST_MINI_OBJECT(buf)));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -820,12 +817,13 @@ _wrap_gst_pad_get_internal_links (PyGObject * self)
|
|||
{
|
||||
PyObject *ret;
|
||||
GList *lst, *tmp;
|
||||
gint i;
|
||||
|
||||
lst = gst_pad_get_internal_links (GST_PAD (pygobject_get(self)));
|
||||
|
||||
ret = PyList_New(0);
|
||||
for (tmp = lst ; tmp; tmp = g_list_next(tmp)) {
|
||||
PyList_Append(ret, pygstobject_new(G_OBJECT(tmp->data)));
|
||||
ret = PyList_New(g_list_length(lst));
|
||||
for (tmp = lst, i = 0 ; tmp; tmp = g_list_next(tmp), ++i) {
|
||||
PyList_SetItem(ret, i, pygstobject_new(G_OBJECT(tmp->data)));
|
||||
}
|
||||
g_list_free(lst);
|
||||
return ret;
|
||||
|
@ -837,12 +835,13 @@ _wrap_gst_pad_get_internal_links_default (PyGObject * self)
|
|||
{
|
||||
PyObject *ret;
|
||||
GList *lst, *tmp;
|
||||
gint i;
|
||||
|
||||
lst = gst_pad_get_internal_links_default (GST_PAD (pygobject_get(self)));
|
||||
|
||||
ret = PyList_New(0);
|
||||
for (tmp = lst ; tmp; tmp = g_list_next(tmp)) {
|
||||
PyList_Append(ret, pygstobject_new(G_OBJECT(tmp->data)));
|
||||
ret = PyList_New(g_list_length(lst));
|
||||
for (tmp = lst, i = 0 ; tmp; tmp = g_list_next(tmp), ++i) {
|
||||
PyList_SetItem(ret, i, pygstobject_new(G_OBJECT(tmp->data)));
|
||||
}
|
||||
g_list_free(lst);
|
||||
return ret;
|
||||
|
@ -865,8 +864,9 @@ _wrap_gst_pad_get_query_types (PyGObject *self)
|
|||
|
||||
ret = PyList_New(0);
|
||||
for (i = 0; tab[i] != 0; i++) {
|
||||
item = pyg_enum_from_gtype (GST_TYPE_QUERY_TYPE, tab[i]);
|
||||
PyList_Append(ret, item);
|
||||
item = pyg_enum_from_gtype (GST_TYPE_QUERY_TYPE, tab[i]);
|
||||
PyList_Append(ret, item);
|
||||
Py_XDECREF(item);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -889,8 +889,9 @@ _wrap_gst_pad_get_query_types_default (PyGObject *self)
|
|||
|
||||
ret = PyList_New(0);
|
||||
for (i = 0; tab[i] != 0; i++) {
|
||||
item = pyg_enum_from_gtype (GST_TYPE_QUERY_TYPE, tab[i]);
|
||||
PyList_Append(ret, item);
|
||||
item = pyg_enum_from_gtype (GST_TYPE_QUERY_TYPE, tab[i]);
|
||||
PyList_Append(ret, item);
|
||||
Py_XDECREF(item);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -36,10 +36,10 @@ _wrap_gst_query_parse_position (PyGstMiniObject *self)
|
|||
|
||||
gst_query_parse_position (GST_QUERY(self->obj), &format, &cur, &end);
|
||||
|
||||
ret = PyList_New(0);
|
||||
PyList_Append(ret, pyg_enum_from_gtype(GST_TYPE_FORMAT, format));
|
||||
PyList_Append(ret, PyLong_FromLongLong(cur));
|
||||
PyList_Append(ret, PyLong_FromLongLong(end));
|
||||
ret = PyList_New(3);
|
||||
PyList_SetItem(ret, 0, pyg_enum_from_gtype(GST_TYPE_FORMAT, format));
|
||||
PyList_SetItem(ret, 1, PyLong_FromLongLong(cur));
|
||||
PyList_SetItem(ret, 2, PyLong_FromLongLong(end));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -61,11 +61,11 @@ _wrap_gst_query_parse_convert (PyGstMiniObject *self)
|
|||
&srcformat, &srcvalue,
|
||||
&destformat, &destvalue);
|
||||
|
||||
ret = PyList_New(0);
|
||||
PyList_Append(ret, pyg_enum_from_gtype(GST_TYPE_FORMAT, srcformat));
|
||||
PyList_Append(ret, PyLong_FromLongLong(srcvalue));
|
||||
PyList_Append(ret, pyg_enum_from_gtype(GST_TYPE_FORMAT, destformat));
|
||||
PyList_Append(ret, PyLong_FromLongLong(destvalue));
|
||||
ret = PyList_New(4);
|
||||
PyList_SetItem(ret, 0, pyg_enum_from_gtype(GST_TYPE_FORMAT, srcformat));
|
||||
PyList_SetItem(ret, 1, PyLong_FromLongLong(srcvalue));
|
||||
PyList_SetItem(ret, 2, pyg_enum_from_gtype(GST_TYPE_FORMAT, destformat));
|
||||
PyList_SetItem(ret, 3, PyLong_FromLongLong(destvalue));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -90,12 +90,12 @@ _wrap_gst_query_parse_segment (PyGstMiniObject *self)
|
|||
&rate, &format,
|
||||
&start_value, &stop_value, &base);
|
||||
|
||||
ret = PyList_New(0);
|
||||
PyList_Append (ret, PyFloat_FromDouble(rate));
|
||||
PyList_Append (ret, pyg_enum_from_gtype (GST_TYPE_FORMAT, format));
|
||||
PyList_Append (ret, PyLong_FromUnsignedLongLong(start_value));
|
||||
PyList_Append (ret, PyLong_FromUnsignedLongLong(stop_value));
|
||||
PyList_Append (ret, PyLong_FromUnsignedLongLong(base));
|
||||
ret = PyList_New(5);
|
||||
PyList_SetItem (ret, 0, PyFloat_FromDouble(rate));
|
||||
PyList_SetItem (ret, 1, pyg_enum_from_gtype (GST_TYPE_FORMAT, format));
|
||||
PyList_SetItem (ret, 2, PyLong_FromUnsignedLongLong(start_value));
|
||||
PyList_SetItem (ret, 3, PyLong_FromUnsignedLongLong(stop_value));
|
||||
PyList_SetItem (ret, 4, PyLong_FromUnsignedLongLong(base));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue