Skip to content
Permalink
Browse files

Simplify and optimise python list->QgsAttributes conversion

  • Loading branch information
nyalldawson committed Jan 29, 2018
1 parent 22de251 commit 878fb951a8172499bed9c8a51d201a8a154348e4
Showing with 18 additions and 18 deletions.
  1. +9 −9 python/core/qgsattributes.sip.in
  2. +9 −9 src/core/qgsattributes.h
@@ -71,19 +71,20 @@ typedef QVector<QVariant> QgsAttributes;
}

QgsAttributes *qv = new QgsAttributes;
SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
qv->reserve( listSize );

for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
{
int state;
PyObject *obj = PyList_GET_ITEM( sipPy, i );
QVariant *t;
if ( obj == Py_None )
{
t = new QVariant( QVariant::Int );
qv->append( QVariant( QVariant::Int ) );
}
else
{
t = reinterpret_cast<QVariant *>( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );
int state;
QVariant *t = reinterpret_cast<QVariant *>( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );

if ( *sipIsErr )
{
@@ -92,11 +93,10 @@ typedef QVector<QVariant> QgsAttributes;
delete qv;
return 0;
}
}

qv->append( *t );

sipReleaseType( t, sipType_QVariant, state );
qv->append( *t );
sipReleaseType( t, sipType_QVariant, state );
}
}

*sipCppPtr = qv;
@@ -175,19 +175,20 @@ typedef QVector<QVariant> QgsAttributes;
}

QgsAttributes *qv = new QgsAttributes;
SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
qv->reserve( listSize );

for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
{
int state;
PyObject *obj = PyList_GET_ITEM( sipPy, i );
QVariant *t;
if ( obj == Py_None )
{
t = new QVariant( QVariant::Int );
qv->append( QVariant( QVariant::Int ) );
}
else
{
t = reinterpret_cast<QVariant *>( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );
int state;
QVariant *t = reinterpret_cast<QVariant *>( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );

if ( *sipIsErr )
{
@@ -196,11 +197,10 @@ typedef QVector<QVariant> QgsAttributes;
delete qv;
return 0;
}
}

qv->append( *t );

sipReleaseType( t, sipType_QVariant, state );
qv->append( *t );
sipReleaseType( t, sipType_QVariant, state );
}
}

*sipCppPtr = qv;

0 comments on commit 878fb95

Please sign in to comment.
You can’t perform that action at this time.