From 3c88e12beb22d8ea11b8a7006a71ba9773c6d183 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 12 Jul 2021 08:14:16 +0200 Subject: QDuplicateTracker: fix the static buffer size calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Pick-to: 6.2 6.1 5.15 Change-Id: I8227a95c49e316aacf3d4efd8f6170ea3bea1cf0 Reviewed-by: Andrei Golubev Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qduplicatetracker_p.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qduplicatetracker_p.h b/src/corelib/tools/qduplicatetracker_p.h index 914ca35815..47c97100f9 100644 --- a/src/corelib/tools/qduplicatetracker_p.h +++ b/src/corelib/tools/qduplicatetracker_p.h @@ -73,7 +73,13 @@ class QDuplicateTracker { } }; - 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> set{&res}; #else -- cgit v1.2.3