path: root/src/corelib/tools/qsharedpointer.cpp
diff options
authorMarc Mutz <>2015-11-12 10:16:22 +0100
committerMarc Mutz <>2015-11-29 22:59:17 +0000
commit51089a5742a79467221b5781cb35a8cea023febf (patch)
tree95f765fa452cdfaa12f986e4d228d9a958c95100 /src/corelib/tools/qsharedpointer.cpp
parent14d189f7875b7def6f9745bfd20527a0fce19a44 (diff)
Use Q_UNLIKELY for every qFatal()/qCritical()
If, after checking a condition, we issue a qFatal() or a qCritical(), by definition that check is unlikely to be true. Tell the compiler so it can move the error handling code out of the normal code path to increase the effective icache size. Moved conditional code around where possible so that we could always use Q_UNLIKELY, instead of having to revert to Q_LIKELY here and there. In some cases, simplified the expressions newly wrapped in Q_UNLIKELY as a drive-by. Change-Id: I67537d62b04bc6977d69254690c5ebbdf98bfd6d Reviewed-by: Konstantin Ritt <> Reviewed-by: Olivier Goffart (Woboq GmbH) <>
Diffstat (limited to 'src/corelib/tools/qsharedpointer.cpp')
1 files changed, 4 insertions, 4 deletions
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp
index 4d30396cb6..b5e27cc720 100644
--- a/src/corelib/tools/qsharedpointer.cpp
+++ b/src/corelib/tools/qsharedpointer.cpp
@@ -1508,7 +1508,7 @@ void QtSharedPointer::internalSafetyCheckAdd(const void *d_ptr, const volatile v
//qDebug("Adding d=%p value=%p", d_ptr, ptr);
const void *other_d_ptr = kp->dataPointers.value(ptr, 0);
- if (other_d_ptr) {
+ if (Q_UNLIKELY(other_d_ptr)) {
# endif
@@ -1539,7 +1539,7 @@ void QtSharedPointer::internalSafetyCheckRemove(const void *d_ptr)
QMutexLocker lock(&kp->mutex);
QHash<const void *, Data>::iterator it = kp->dPointers.find(d_ptr);
- if (it == kp->dPointers.end()) {
+ if (Q_UNLIKELY(it == kp->dPointers.end())) {
qFatal("QSharedPointer: internal self-check inconsistency: pointer %p was not tracked. "
"To use QT_SHAREDPOINTER_TRACK_POINTERS, you have to enable it throughout "
"in your code.", d_ptr);
@@ -1566,10 +1566,10 @@ void QtSharedPointer::internalSafetyCheckCleanCheck()
KnownPointers *const kp = knownPointers();
Q_ASSERT_X(kp, "internalSafetyCheckSelfCheck()", "Called after global statics deletion!");
- if (kp->dPointers.size() != kp->dataPointers.size())
+ if (Q_UNLIKELY(kp->dPointers.size() != kp->dataPointers.size()))
qFatal("Internal consistency error: the number of pointers is not equal!");
- if (!kp->dPointers.isEmpty())
+ if (Q_UNLIKELY(!kp->dPointers.isEmpty()))
qFatal("Pointer cleaning failed: %d entries remaining", kp->dPointers.size());
# endif