Use the fast operator+ (in the form of operator%)
QStringBuilder will precalculate the size of the string for us, which avoids extra realloc() and moving data around. Change-Id: I4e31964bb9bfffbe2083b3cb8c120e602160dfd8 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com> Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com>bb10
parent
688b006cc8
commit
6cdc033c61
|
|
@ -142,13 +142,10 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys()
|
|||
{
|
||||
// Assemble data, to write in a single call to write
|
||||
// (otherwise we'd have to check every write call)
|
||||
QByteArray fileData;
|
||||
fileData += QByteArray::number(QCoreApplication::applicationPid());
|
||||
fileData += '\n';
|
||||
fileData += qAppName().toUtf8();
|
||||
fileData += '\n';
|
||||
fileData += localHostName().toUtf8();
|
||||
fileData += '\n';
|
||||
// Use operator% from the fast builder to avoid multiple memory allocations.
|
||||
QByteArray fileData = QByteArray::number(QCoreApplication::applicationPid()) % '\n'
|
||||
% qAppName().toUtf8() % '\n'
|
||||
% localHostName().toUtf8() % '\n';
|
||||
|
||||
const QByteArray lockFileName = QFile::encodeName(fileName);
|
||||
const int fd = qt_safe_open(lockFileName.constData(), O_WRONLY | O_CREAT | O_EXCL, 0644);
|
||||
|
|
|
|||
Loading…
Reference in New Issue