diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-03-01 18:56:47 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-03-02 19:53:51 +0100 |
commit | 7032afbb5e7b3580fbe5185b651b86c2fe3145c1 (patch) | |
tree | 4531abd378e15e3d6bc5004ed55a5490af0caa7d /sources/shiboken6/tests/samplebinding/typesystem_sample.xml | |
parent | 79676495d188359b805c04ce4e983078772f4ca5 (diff) |
Modernize sequence conversions
- Use correct size types
- Use const iterators
- Avoid repeated invocation of end()/size()
Task-number: PYSIDE-1438
Change-Id: I7d30a5c87d0867400134be96ee61ff1ab6129435
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6/tests/samplebinding/typesystem_sample.xml')
-rw-r--r-- | sources/shiboken6/tests/samplebinding/typesystem_sample.xml | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml index 20fa61334..a8b7b3b11 100644 --- a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml +++ b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml @@ -388,9 +388,9 @@ </conversion-rule> </container-type> <template name="cpplist_to_pylist_convertion"> - PyObject* %out = PyList_New((int) %in.size()); - %INTYPE::const_iterator it = %in.begin(); - for (int idx = 0; it != %in.end(); ++it, ++idx) { + PyObject *%out = PyList_New(Py_ssize_t(%in.size())); + Py_ssize_t idx = 0; + for (auto it = %in.cbegin(), end = %in.cend(); it != end; ++it, ++idx) { %INTYPE_0 cppItem(*it); PyList_SET_ITEM(%out, idx, %CONVERTTOPYTHON[%INTYPE_0](cppItem)); } @@ -398,7 +398,8 @@ </template> <template name="pyseq_to_cpplist_convertion"> Shiboken::AutoDecRef seq(PySequence_Fast(%in, 0)); - for (int i = 0; i < PySequence_Fast_GET_SIZE(seq.object()); i++) { + const Py_ssize_t size = PySequence_Fast_GET_SIZE(seq.object()); + for (Py_ssize_t i = 0; i < size; ++i) { PyObject* pyItem = PySequence_Fast_GET_ITEM(seq.object(), i); %OUTTYPE_0 cppItem = %CONVERTTOCPP[%OUTTYPE_0](pyItem); %out.push_back(cppItem); @@ -435,8 +436,7 @@ <conversion-rule> <native-to-target> PyObject* %out = PyDict_New(); - %INTYPE::const_iterator it = %in.begin(); - for (; it != %in.end(); ++it) { + for (auto it = %in.cbegin(), end = %in.cend(); it != end; ++it) { %INTYPE_0 key = it->first; %INTYPE_1 value = it->second; PyDict_SetItem(%out, @@ -453,7 +453,7 @@ while (PyDict_Next(%in, &pos, &key, &value)) { %OUTTYPE_0 cppKey = %CONVERTTOCPP[%OUTTYPE_0](key); %OUTTYPE_1 cppValue = %CONVERTTOCPP[%OUTTYPE_1](value); - %out.insert(%OUTTYPE::value_type(cppKey, cppValue)); + %out.insert({cppKey, cppValue}); } </add-conversion> </target-to-native> |