QDuplicateTracker: allow usage of qHash
The codepath using unordered_set forced the usage of std::hash, which isn't provided by many Qt types. Instead, use the brand new helpers in QHash that dispatch to qHash with a fallback on std::hash. Change-Id: I9185fe9c52de05c470afe7466007591977e65bb1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
7a32a2d809
commit
06957af471
@ -55,6 +55,7 @@
|
||||
#if QT_HAS_INCLUDE(<memory_resource>) && __cplusplus > 201402L
|
||||
# include <unordered_set>
|
||||
# include <memory_resource>
|
||||
# include <qhash.h> // for the hashing helpers
|
||||
#else
|
||||
# include <qset.h>
|
||||
#endif
|
||||
@ -64,9 +65,16 @@ QT_BEGIN_NAMESPACE
|
||||
template <typename T, size_t Prealloc = 32>
|
||||
class QDuplicateTracker {
|
||||
#ifdef __cpp_lib_memory_resource
|
||||
template <typename HT>
|
||||
struct QHasher {
|
||||
size_t operator()(const HT &t) const {
|
||||
return QHashPrivate::calculateHash(t, qGlobalQHashSeed());
|
||||
}
|
||||
};
|
||||
|
||||
char buffer[Prealloc * sizeof(T)];
|
||||
std::pmr::monotonic_buffer_resource res{buffer, sizeof buffer};
|
||||
std::pmr::unordered_set<T> set{&res};
|
||||
std::pmr::unordered_set<T, QHasher<T>> set{&res};
|
||||
#else
|
||||
QSet<T> set;
|
||||
int setSize = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user