diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-01-16 18:01:11 -0800 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-18 04:39:23 +0100 |
commit | 5fcee880975c0ee9e373b097209882fbd30add0b (patch) | |
tree | 7ea64243e3d9fffbaafbd827f192bfac8488e84b /src/corelib/tools/qstringbuilder.h | |
parent | 556c3209e2067664d6774ac049000d2aa05f5d85 (diff) |
Abuse const_cast in QStringBuilder to get a little more performance
Without this const_cast, the call to QString::data() or
QByteArray::data() will cause a call to detach(), which is totally
unnecessary since we've just allocated data a couple of lines before.
Since we know we're the owner of the only reference, we can skip the
detach attempt.
Change-Id: If40f66100f85cc9b405025f21c562828ead23475
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/tools/qstringbuilder.h')
-rw-r--r-- | src/corelib/tools/qstringbuilder.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/corelib/tools/qstringbuilder.h b/src/corelib/tools/qstringbuilder.h index e09b02b5a9..489357f5fd 100644 --- a/src/corelib/tools/qstringbuilder.h +++ b/src/corelib/tools/qstringbuilder.h @@ -112,7 +112,9 @@ private: const uint len = QConcatenable< QStringBuilder<A, B> >::size(*this); T s(len, Qt::Uninitialized); - typename T::iterator d = s.data(); + // we abuse const_cast / constData here because we know we've just + // allocated the data and we're the only reference count + typename T::iterator d = const_cast<typename T::iterator>(s.constData()); typename T::const_iterator const start = d; QConcatenable< QStringBuilder<A, B> >::appendTo(*this, d); |