Skip to content

Commit

Permalink
Simplify and optimise python list->QgsAttributes conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 29, 2018
1 parent 22de251 commit 878fb95
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions python/core/qgsattributes.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/core/qgsattributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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;
Expand Down

0 comments on commit 878fb95

Please sign in to comment.