diff options
author | John Cummings <jcummings2@users.sf.net> | 2012-06-01 15:29:38 -0500 |
---|---|---|
committer | Hugo Parente Lima <hugo.lima@openbossa.org> | 2012-06-01 23:47:51 +0200 |
commit | ee95e881929b3b51e535ad9024025cc7ac91d57c (patch) | |
tree | 79d10f9491415460b5ce3737434453ea36775457 | |
parent | a090ae9340b6ef8b135919c69ca377f763e138ad (diff) |
Improved QVector to python conversion
Added pyseq_to_cppvector_conversion template that calls
reserve() with the sequence size to reduce memory reallocations
Changed QVector conversion to use new the template
Change-Id: I099ab15d5f725499218e2ed081a325246aa5b902
Reviewed-by: Hugo Parente Lima <hugo.lima@openbossa.org>
-rw-r--r-- | PySide/QtCore/typesystem_core_common.xml | 2 | ||||
-rw-r--r-- | PySide/typesystem_templates.xml | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/PySide/QtCore/typesystem_core_common.xml b/PySide/QtCore/typesystem_core_common.xml index 5ef1466f..4a5e6267 100644 --- a/PySide/QtCore/typesystem_core_common.xml +++ b/PySide/QtCore/typesystem_core_common.xml @@ -603,7 +603,7 @@ </native-to-target> <target-to-native> <add-conversion type="PySequence"> - <insert-template name="pyseq_to_cpplist_convertion"/> + <insert-template name="pyseq_to_cppvector_conversion"/> </add-conversion> </target-to-native> </conversion-rule> diff --git a/PySide/typesystem_templates.xml b/PySide/typesystem_templates.xml index 2903ae40..61b1471d 100644 --- a/PySide/typesystem_templates.xml +++ b/PySide/typesystem_templates.xml @@ -413,6 +413,15 @@ %out << cppItem; } </template> + <template name="pyseq_to_cppvector_conversion"> + int the_size = PySequence_Size(%in); + %out.reserve(the_size); + for (int i = 0; i < the_size; ++i) { + Shiboken::AutoDecRef pyItem(PySequence_GetItem(%in, i)); + %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); + %out << cppItem; + } + </template> <template name="checkPyCapsuleOrPyCObject_func"> static bool checkPyCapsuleOrPyCObject(PyObject* pyObj) |