summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2013-10-09 11:38:44 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-15 23:58:09 +0200
commit6cdc033c61eeca5303fd271d28003f8617f9f830 (patch)
treeb0019a16aeca146e6ebc9fa79a9cc60e2b09a6b9 /src/corelib/io
parent688b006cc8d8d4d9ce1f29049f96d4d590bb60d7 (diff)
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>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qlockfile_unix.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp
index de21ee217a..dc8817706c 100644
--- a/src/corelib/io/qlockfile_unix.cpp
+++ b/src/corelib/io/qlockfile_unix.cpp
@@ -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);