Avoid copying QByteArray created via fromRawData in toDouble

qt_asciiToDouble accepts a length parameter, so we can just pass
that through. No need for explicitly null-terminating, which is
where the copy of the data would be made.

Change-Id: I4e7921541f03295a2fae6171b35157084ff3ed8c
Fixes: QTBUG-65748
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Volker Hilsheimer 2019-03-06 10:00:09 +01:00
parent 261c0dedac
commit 75c6bd54d7
2 changed files with 4 additions and 2 deletions

View File

@ -4135,10 +4135,9 @@ ushort QByteArray::toUShort(bool *ok, int base) const
double QByteArray::toDouble(bool *ok) const
{
QByteArray nulled = nulTerminated();
bool nonNullOk = false;
int processed = 0;
double d = qt_asciiToDouble(nulled.constData(), nulled.length(),
double d = qt_asciiToDouble(constData(), size(),
nonNullOk, processed, WhitespacesAllowed);
if (ok)
*ok = nonNullOk;

View File

@ -1361,6 +1361,9 @@ void tst_QByteArray::toDouble_data()
QTest::newRow("trailing spaces") << QByteArray("1.2345 \n\r\t") << 1.2345 << true;
QTest::newRow("leading junk") << QByteArray("x1.2345") << 0.0 << false;
QTest::newRow("trailing junk") << QByteArray("1.2345x") << 0.0 << false;
QTest::newRow("raw, null plus junk") << QByteArray::fromRawData("1.2\0 junk", 9) << 0.0 << false;
QTest::newRow("raw, null-terminator not included") << QByteArray::fromRawData("2.3", 3) << 2.3 << true;
}
void tst_QByteArray::toDouble()