summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qsharedpointer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qsharedpointer.cpp')
-rw-r--r--src/corelib/tools/qsharedpointer.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp
index 86f4c6a268..24eee1d1b8 100644
--- a/src/corelib/tools/qsharedpointer.cpp
+++ b/src/corelib/tools/qsharedpointer.cpp
@@ -1292,6 +1292,17 @@
compile. Use qSharedPointerConstCast to cast away the constness.
*/
+/*!
+ \fn QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr)
+ \relates QSharedPointer
+ \since 5.7
+
+ Writes the pointer tracked by \a ptr into the debug object \a debug for
+ debugging purposes.
+
+ \sa {Debugging Techniques}
+*/
+
#include <qset.h>
#include <qmutex.h>
@@ -1497,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)) {
# ifdef BACKTRACE_SUPPORTED
printBacktrace(knownPointers()->dPointers.value(other_d_ptr).backtrace);
# endif
@@ -1527,15 +1538,15 @@ 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()) {
+ const auto it = kp->dPointers.constFind(d_ptr);
+ if (Q_UNLIKELY(it == kp->dPointers.cend())) {
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);
}
- QHash<const volatile void *, const void *>::iterator it2 = kp->dataPointers.find(it->pointer);
- Q_ASSERT(it2 != kp->dataPointers.end());
+ const auto it2 = kp->dataPointers.constFind(it->pointer);
+ Q_ASSERT(it2 != kp->dataPointers.cend());
//qDebug("Removing d=%p value=%p", d_ptr, it->pointer);
@@ -1555,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
}