SQL: small optimization for SQLDriver::escapeIdentifier()

Avoid a memmove (and replace it with a memcpy) by not using
QString::prepend() but create a completely new string object instead.

Change-Id: Ibdb4a9c6b15b96f1743d47e158ff0fb9b2048221
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
Christian Ehrlicher 2023-02-16 20:13:46 +01:00
parent 79b22bb1f3
commit 9b643bc6c9
6 changed files with 9 additions and 8 deletions

View File

@ -1699,8 +1699,8 @@ QString QDB2Driver::escapeIdentifier(const QString &identifier, IdentifierType)
QString res = identifier;
if (!identifier.isEmpty() && !identifier.startsWith(u'"') && !identifier.endsWith(u'"') ) {
res.replace(u'"', "\"\""_L1);
res.prepend(u'"').append(u'"');
res.replace(u'.', "\".\""_L1);
res = u'"' + res + u'"';
}
return res;
}

View File

@ -1860,8 +1860,8 @@ QString QIBaseDriver::escapeIdentifier(const QString &identifier, IdentifierType
QString res = identifier;
if (!identifier.isEmpty() && !identifier.startsWith(u'"') && !identifier.endsWith(u'"') ) {
res.replace(u'"', "\"\""_L1);
res.prepend(u'"').append(u'"');
res.replace(u'.', "\".\""_L1);
res = u'"' + res + u'"';
}
return res;
}

View File

@ -2753,8 +2753,8 @@ QString QOCIDriver::escapeIdentifier(const QString &identifier, IdentifierType t
QString res = identifier;
if (!identifier.isEmpty() && !isIdentifierEscaped(identifier, type)) {
res.replace(u'"', "\"\""_L1);
res.prepend(u'"').append(u'"');
res.replace(u'.', "\".\""_L1);
res = u'"' + res + u'"';
}
return res;
}

View File

@ -2598,9 +2598,10 @@ QString QODBCDriver::escapeIdentifier(const QString &identifier, IdentifierType)
QChar quote = const_cast<QODBCDriverPrivate*>(d)->quoteChar();
QString res = identifier;
if (!identifier.isEmpty() && !identifier.startsWith(quote) && !identifier.endsWith(quote) ) {
res.replace(quote, QString(quote)+QString(quote));
res.prepend(quote).append(quote);
res.replace(u'.', QString(quote) + u'.' +QString(quote));
const QString quoteStr(quote);
res.replace(quote, quoteStr + quoteStr);
res.replace(u'.', quoteStr + u'.' + quoteStr);
res = quote + res + quote;
}
return res;
}

View File

@ -1516,8 +1516,8 @@ QString QPSQLDriver::escapeIdentifier(const QString &identifier, IdentifierType)
QString res = identifier;
if (!identifier.isEmpty() && !identifier.startsWith(u'"') && !identifier.endsWith(u'"') ) {
res.replace(u'"', "\"\""_L1);
res.prepend(u'"').append(u'"');
res.replace(u'.', "\".\""_L1);
res = u'"' + res + u'"';
}
return res;
}

View File

@ -49,9 +49,9 @@ static QString _q_escapeIdentifier(const QString &identifier, QSqlDriver::Identi
return res;
if (!identifier.isEmpty() && !identifier.startsWith(u'"') && !identifier.endsWith(u'"')) {
res.replace(u'"', "\"\""_L1);
res.prepend(u'"').append(u'"');
if (type == QSqlDriver::TableName)
res.replace(u'.', "\".\""_L1);
res = u'"' + res + u'"';
}
return res;
}