Skip to content

Commit

Permalink
Optimise comparison of date/time/datetime values in expressions
Browse files Browse the repository at this point in the history
Avoid forced conversion to string when comparing the same date/time
types
  • Loading branch information
nyalldawson committed May 8, 2020
1 parent e9bc483 commit 61f1566
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/core/expression/qgsexpressionnodeimpl.cpp
Expand Up @@ -403,6 +403,30 @@ QVariant QgsExpressionNodeBinaryOperator::evalNode( QgsExpression *parent, const
return TVL_Unknown;
}
}
else if ( ( vL.type() == QVariant::DateTime && vR.type() == QVariant::DateTime ) )
{
const QDateTime dL = QgsExpressionUtils::getDateTimeValue( vL, parent );
ENSURE_NO_EVAL_ERROR;
const QDateTime dR = QgsExpressionUtils::getDateTimeValue( vR, parent );
ENSURE_NO_EVAL_ERROR;
return compare( dR.msecsTo( dL ) ) ? TVL_True : TVL_False;
}
else if ( ( vL.type() == QVariant::Date && vR.type() == QVariant::Date ) )
{
const QDate dL = QgsExpressionUtils::getDateValue( vL, parent );
ENSURE_NO_EVAL_ERROR;
const QDate dR = QgsExpressionUtils::getDateValue( vR, parent );
ENSURE_NO_EVAL_ERROR;
return compare( dR.daysTo( dL ) ) ? TVL_True : TVL_False;
}
else if ( ( vL.type() == QVariant::Time && vR.type() == QVariant::Time ) )
{
const QTime dL = QgsExpressionUtils::getTimeValue( vL, parent );
ENSURE_NO_EVAL_ERROR;
const QTime dR = QgsExpressionUtils::getTimeValue( vR, parent );
ENSURE_NO_EVAL_ERROR;
return compare( dR.msecsTo( dL ) ) ? TVL_True : TVL_False;
}
else if ( ( vL.type() != QVariant::String || vR.type() != QVariant::String ) &&
QgsExpressionUtils::isDoubleSafe( vL ) && QgsExpressionUtils::isDoubleSafe( vR ) )
{
Expand Down

0 comments on commit 61f1566

Please sign in to comment.