From 81ba262a62a3b7517057e59db1a931ef452e4e52 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 23 Oct 2024 19:47:28 +0200 Subject: [PATCH] SQL/Mimer: simplify uuid conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplify converting a QUuid to a rfc4122 representation by using the built-in toRfc4122() function and don't allocate a temporary QByteArray when converting it back from rfc4122 to a QUuid. As a drive-by make sure to not detach when converting a QByteArray to a blob. Change-Id: Ib8fc7744952377d14ef39c0d901a6a8419eb018d Reviewed-by: Fredrik Ă…lund Reviewed-by: Axel Spoerl (cherry picked from commit 814e4e1cbe6e4a625625942c70b394aa6455fb19) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/sqldrivers/mimer/qsql_mimer.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/plugins/sqldrivers/mimer/qsql_mimer.cpp b/src/plugins/sqldrivers/mimer/qsql_mimer.cpp index 7f89e0a0d57..f80c42fac87 100644 --- a/src/plugins/sqldrivers/mimer/qsql_mimer.cpp +++ b/src/plugins/sqldrivers/mimer/qsql_mimer.cpp @@ -845,7 +845,7 @@ QVariant QMimerSQLResult::data(int i) err, QSqlError::StatementError, d->drv_d_func())); return QVariant(QMetaType(type), nullptr); } - const QByteArray uuidByteArray = QByteArray(reinterpret_cast(uuidChar), 16); + const auto uuidByteArray = QByteArrayView(reinterpret_cast(uuidChar), 16); return QUuid::fromRfc4122(uuidByteArray); } case MimerColumnTypes::Unknown: @@ -1084,8 +1084,7 @@ bool QMimerSQLResult::exec() break; } case MimerColumnTypes::Uuid: { - const QByteArray uuidArray = - QByteArray::fromHex(val.toUuid().toString(QUuid::WithoutBraces).toLatin1()); + const QByteArray uuidArray = val.toUuid().toRfc4122(); const unsigned char *uuid = reinterpret_cast(uuidArray.constData()); err = MimerSetUUID(d->statementhandle, i + 1, uuid); @@ -1152,7 +1151,7 @@ bool QMimerSQLResult::exec() break; } case MimerColumnTypes::Blob: { - QByteArray blobArr = val.toByteArray(); + const QByteArray blobArr = val.toByteArray(); const char *blobData = blobArr.constData(); qsizetype size = blobArr.size(); err = MimerSetLob(d->statementhandle, i + 1, size, &d->lobhandle);