diff options
author | Robert Szefner <r.szefner@hydro-partner.pl> | 2019-03-11 00:23:31 +0100 |
---|---|---|
committer | Robert Szefner <robertsz27@interia.pl> | 2019-03-11 13:18:38 +0000 |
commit | 52c0bb59945f5068c84238619411078a1c67620f (patch) | |
tree | b4198ce241bcf6293c5b0115559bc685b597bfee | |
parent | 0a02de62d1fe4341684df370242fd3aca3b21f9d (diff) |
QPSQL: Use qstrtod() function for string to double conversion
A change to qstrtod() will give us a small performance improvement.
Because the qstrtod() function does not correctly parse the NaN values,
an appropriate check condition for NaN has been added.
Also changed code structure so now the double conversion function
is called only in one place.
Task-number: QTBUG-65748
Change-Id: I49d40e5157e79cc5fce35db4c4272d1ccd270c6b
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
-rw-r--r-- | src/plugins/sqldrivers/psql/qsql_psql.cpp | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 49b793ce38..fe4bb4b464 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -53,6 +53,7 @@ #include <qlocale.h> #include <QtSql/private/qsqlresult_p.h> #include <QtSql/private/qsqldriver_p.h> +#include <QtCore/private/qlocale_tools_p.h> #include <queue> @@ -663,27 +664,30 @@ QVariant QPSQLResult::data(int i) return atoi(val); case QVariant::Double: { if (ptype == QNUMERICOID) { - if (numericalPrecisionPolicy() != QSql::HighPrecision) { - QVariant retval; - bool convert; - double dbl=QString::fromLatin1(val).toDouble(&convert); - if (numericalPrecisionPolicy() == QSql::LowPrecisionInt64) - retval = (qlonglong)dbl; - else if (numericalPrecisionPolicy() == QSql::LowPrecisionInt32) - retval = (int)dbl; - else if (numericalPrecisionPolicy() == QSql::LowPrecisionDouble) - retval = dbl; - if (!convert) - return QVariant(); - return retval; - } - return QString::fromLatin1(val); + if (numericalPrecisionPolicy() == QSql::HighPrecision) + return QString::fromLatin1(val); + } + bool ok; + double dbl = qstrtod(val, nullptr, &ok); + if (!ok) { + if (qstricmp(val, "NaN") == 0) + dbl = qQNaN(); + else if (qstricmp(val, "Infinity") == 0) + dbl = qInf(); + else if (qstricmp(val, "-Infinity") == 0) + dbl = -qInf(); + else + return QVariant(); + } + if (ptype == QNUMERICOID) { + if (numericalPrecisionPolicy() == QSql::LowPrecisionInt64) + return QVariant((qlonglong)dbl); + else if (numericalPrecisionPolicy() == QSql::LowPrecisionInt32) + return QVariant((int)dbl); + else if (numericalPrecisionPolicy() == QSql::LowPrecisionDouble) + return QVariant(dbl); } - if (qstricmp(val, "Infinity") == 0) - return qInf(); - if (qstricmp(val, "-Infinity") == 0) - return -qInf(); - return QString::fromLatin1(val).toDouble(); + return dbl; } case QVariant::Date: if (val[0] == '\0') { |