summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-07-12 08:14:16 +0200
committerMarc Mutz <marc.mutz@kdab.com>2021-07-14 07:27:45 +0000
commit8c0dacb5e18427254e337c4a305b762a97c5c364 (patch)
treeb971f888db5fe322250e6bacf249e0a1e31b7889
parent78ca39fbb06dc87dbfd87952e4cc67e3c5141297 (diff)
QDuplicateTracker: fix the static buffer size calculation
Instead of just sizeof(T), we, of course, also need to take the support structure into account, to wit: the bucket list and, in the node, the next pointer and the stored hash value. Change-Id: I8227a95c49e316aacf3d4efd8f6170ea3bea1cf0 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> (cherry picked from commit 3c88e12beb22d8ea11b8a7006a71ba9773c6d183)
-rw-r--r--src/corelib/tools/qduplicatetracker_p.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/corelib/tools/qduplicatetracker_p.h b/src/corelib/tools/qduplicatetracker_p.h
index 9a3385620d..ed7053fce9 100644
--- a/src/corelib/tools/qduplicatetracker_p.h
+++ b/src/corelib/tools/qduplicatetracker_p.h
@@ -64,7 +64,13 @@ 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};
#else