summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qduplicatetracker_p.h13
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h6
-rw-r--r--src/corelib/tools/qvarlengtharray.h2
3 files changed, 12 insertions, 9 deletions
diff --git a/src/corelib/tools/qduplicatetracker_p.h b/src/corelib/tools/qduplicatetracker_p.h
index 99068c01a3..68284fb916 100644
--- a/src/corelib/tools/qduplicatetracker_p.h
+++ b/src/corelib/tools/qduplicatetracker_p.h
@@ -64,11 +64,18 @@ QT_BEGIN_NAMESPACE
template <typename T, size_t Prealloc = 32>
class QDuplicateTracker {
#ifdef __cpp_lib_memory_resource
- char buffer[Prealloc * sizeof(T)];
+ struct node_guesstimate { void *next; size_t hash; T value; };
+ static constexpr size_t bufferSize(size_t N) {
+ return N * sizeof(void*) // bucket list
+ + N * sizeof(node_guesstimate); // nodes
+ }
+
+ char buffer[bufferSize(Prealloc)];
std::pmr::monotonic_buffer_resource res{buffer, sizeof buffer};
- std::pmr::unordered_set<T> set{&res};
+ std::pmr::unordered_set<T> set{Prealloc, &res};
#else
- QSet<T> set;
+ static QSet<T> makeQSet() { QSet<T> r; r.reserve(Prealloc); return r; }
+ QSet<T> set = makeQSet();
int setSize = 0;
#endif
Q_DISABLE_COPY_MOVE(QDuplicateTracker);
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 790c187cb9..8abb57586b 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -1012,15 +1012,11 @@ std::shared_ptr<X> qobject_pointer_cast(std::shared_ptr<T> &&src)
using element_type = typename std::shared_ptr<X>::element_type;
auto castResult = qobject_cast<element_type *>(src.get());
if (castResult) {
- auto result = std::shared_ptr<X>(std::move(src), castResult);
-#if __cplusplus <= 201703L
// C++2a's move aliasing constructor will leave src empty.
// Before C++2a we don't really know if the compiler has support for it.
// The move aliasing constructor is the resolution for LWG2996,
// which does not impose a feature-testing macro. So: clear src.
- src.reset();
-#endif
- return result;
+ return std::shared_ptr<X>(qExchange(src, nullptr), castResult);
}
return std::shared_ptr<X>();
}
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index fd0c99c032..0110956b77 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -507,8 +507,8 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthA
int offset = int(before - ptr);
if (n != 0) {
+ const T copy(t); // `t` could alias an element in [begin(), end()[
resize(s + n);
- const T copy(t);
if (!QTypeInfoQuery<T>::isRelocatable) {
T *b = ptr + offset;
T *j = ptr + s;