mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-27 00:07:16 -05:00
Additional shortcut to QgsAttributes creation from Python
Avoid constructing a bunch of default QVariant objects which we will just replace immediately
This commit is contained in:
parent
280cd84652
commit
6185675c93
@ -70,9 +70,12 @@ typedef QVector<QVariant> QgsAttributes;
|
||||
return 1;
|
||||
}
|
||||
|
||||
QgsAttributes *qv = new QgsAttributes;
|
||||
Py_ssize_t listSize = PyList_GET_SIZE( sipPy );
|
||||
qv->resize( listSize );
|
||||
// Initialize attributes to null. This has two motivations:
|
||||
// 1. It speeds up the QVector construction, as otherwise we are creating n default QVariant objects (default QVariant constructor is not free!)
|
||||
// 2. It lets us shortcut in the loop below when a Py_None is encountered in the list
|
||||
const QVariant nullVariant( QVariant::Int );
|
||||
QgsAttributes *qv = new QgsAttributes( listSize, nullVariant );
|
||||
QVariant *outData = qv->data();
|
||||
|
||||
for ( Py_ssize_t i = 0; i < listSize; ++i )
|
||||
@ -80,7 +83,8 @@ typedef QVector<QVariant> QgsAttributes;
|
||||
PyObject *obj = PyList_GET_ITEM( sipPy, i );
|
||||
if ( obj == Py_None )
|
||||
{
|
||||
*outData++ = QVariant( QVariant::Int );
|
||||
// outData was already initialized to null values
|
||||
*outData++;
|
||||
}
|
||||
else if ( PyBool_Check( obj ) )
|
||||
{
|
||||
|
||||
@ -70,9 +70,12 @@ typedef QVector<QVariant> QgsAttributes;
|
||||
return 1;
|
||||
}
|
||||
|
||||
QgsAttributes *qv = new QgsAttributes;
|
||||
SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
|
||||
qv->resize( listSize );
|
||||
// Initialize attributes to null. This has two motivations:
|
||||
// 1. It speeds up the QVector construction, as otherwise we are creating n default QVariant objects (default QVariant constructor is not free!)
|
||||
// 2. It lets us shortcut in the loop below when a Py_None is encountered in the list
|
||||
const QVariant nullVariant( QVariant::Int );
|
||||
QgsAttributes *qv = new QgsAttributes( listSize, nullVariant );
|
||||
QVariant *outData = qv->data();
|
||||
|
||||
for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
|
||||
@ -80,7 +83,8 @@ typedef QVector<QVariant> QgsAttributes;
|
||||
PyObject *obj = PyList_GET_ITEM( sipPy, i );
|
||||
if ( obj == Py_None )
|
||||
{
|
||||
*outData++ = QVariant( QVariant::Int );
|
||||
// outData was already initialized to null values
|
||||
*outData++;
|
||||
}
|
||||
else if ( PyBool_Check( obj ) )
|
||||
{
|
||||
|
||||
@ -190,9 +190,12 @@ typedef QVector<QVariant> QgsAttributes;
|
||||
return 1;
|
||||
}
|
||||
|
||||
QgsAttributes *qv = new QgsAttributes;
|
||||
SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
|
||||
qv->resize( listSize );
|
||||
// Initialize attributes to null. This has two motivations:
|
||||
// 1. It speeds up the QVector construction, as otherwise we are creating n default QVariant objects (default QVariant constructor is not free!)
|
||||
// 2. It lets us shortcut in the loop below when a Py_None is encountered in the list
|
||||
const QVariant nullVariant( QVariant::Int );
|
||||
QgsAttributes *qv = new QgsAttributes( listSize, nullVariant );
|
||||
QVariant *outData = qv->data();
|
||||
|
||||
for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
|
||||
@ -200,7 +203,8 @@ typedef QVector<QVariant> QgsAttributes;
|
||||
PyObject *obj = PyList_GET_ITEM( sipPy, i );
|
||||
if ( obj == Py_None )
|
||||
{
|
||||
*outData++ = QVariant( QVariant::Int );
|
||||
// outData was already initialized to null values
|
||||
*outData++;
|
||||
}
|
||||
else if ( PyBool_Check( obj ) )
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user