aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Cummings <jcummings2@users.sf.net>2012-06-01 15:29:38 -0500
committerHugo Parente Lima <hugo.lima@openbossa.org>2012-06-01 23:47:51 +0200
commitee95e881929b3b51e535ad9024025cc7ac91d57c (patch)
tree79d10f9491415460b5ce3737434453ea36775457
parenta090ae9340b6ef8b135919c69ca377f763e138ad (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.xml2
-rw-r--r--PySide/typesystem_templates.xml9
2 files changed, 10 insertions, 1 deletions
diff --git a/PySide/QtCore/typesystem_core_common.xml b/PySide/QtCore/typesystem_core_common.xml
index 5ef1466fc..4a5e62672 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 2903ae408..61b1471de 100644
--- a/PySide/typesystem_templates.xml
+++ b/PySide/typesystem_templates.xml
@@ -413,6 +413,15 @@
%out &lt;&lt; cppItem;
}
</template>
+ <template name="pyseq_to_cppvector_conversion">
+ int the_size = PySequence_Size(%in);
+ %out.reserve(the_size);
+ for (int i = 0; i &lt; the_size; ++i) {
+ Shiboken::AutoDecRef pyItem(PySequence_GetItem(%in, i));
+ %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem);
+ %out &lt;&lt; cppItem;
+ }
+ </template>
<template name="checkPyCapsuleOrPyCObject_func">
static bool checkPyCapsuleOrPyCObject(PyObject* pyObj)