diff options
author | John Cummings <jcummings2@users.sf.net> | 2012-06-14 16:10:56 -0500 |
---|---|---|
committer | Hugo Parente Lima <hugo.lima@openbossa.org> | 2012-06-14 23:50:44 +0200 |
commit | c00a1f7ffd313d7e0363a1d386d2bd6e7db3feb6 (patch) | |
tree | d0b4d1fd4186951d1576f88760cf41cad8866459 | |
parent | ee9cda9b0bbe877d303d9838ce0af5623b484abb (diff) |
Optimize vector to pylist conversion
Incorporate changes from Shiboken change I5f0c93b7
Note switch to push_back() should allow the template to work
for both QVector and std::vector.
Likewise, using size_type should avoid compiler warnings.
Change-Id: I4742aa9030e1bfa2e070f4b6f71d124d3c99749d
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 | 19 |
2 files changed, 15 insertions, 6 deletions
diff --git a/PySide/QtCore/typesystem_core_common.xml b/PySide/QtCore/typesystem_core_common.xml index 91cbda81d..d7d0dd9a4 100644 --- a/PySide/QtCore/typesystem_core_common.xml +++ b/PySide/QtCore/typesystem_core_common.xml @@ -599,7 +599,7 @@ <include file-name="QVector" location="global"/> <conversion-rule> <native-to-target> - <insert-template name="cpplist_to_pylist_conversion"/> + <insert-template name="cppvector_to_pylist_conversion"/> </native-to-target> <target-to-native> <add-conversion type="PySequence"> diff --git a/PySide/typesystem_templates.xml b/PySide/typesystem_templates.xml index 2c93e16dc..cf1782076 100644 --- a/PySide/typesystem_templates.xml +++ b/PySide/typesystem_templates.xml @@ -413,13 +413,22 @@ %out << cppItem; } </template> + <template name="cppvector_to_pylist_conversion"> + %INTYPE::size_type vectorSize = %in.size(); + PyObject* %out = PyList_New((int) vectorSize); + for (%INTYPE::size_type idx = 0; idx < vectorSize; ++idx) { + %INTYPE_0 cppItem(%in[idx]); + PyList_SET_ITEM(%out, idx, %CONVERTTOPYTHON[%INTYPE_0](cppItem)); + } + return %out; + </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)); + int vectorSize = PySequence_Size(%in); + %out.reserve(vectorSize); + for (int idx = 0; idx < vectorSize; ++idx) { + Shiboken::AutoDecRef pyItem(PySequence_GetItem(%in, idx)); %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); - %out << cppItem; + %out.push_back(cppItem); } </template> |