From 814d639b66840afa593f230de9c776182b043ee2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 6 Feb 2023 13:39:03 -0800 Subject: [PATCH] qmath: add qNextPowerOfTwo(unsigned long) - for size_t This completes the triad uint/ulong/qulonglong, ensuring that one of them will be size_t and one of them will be uintptr_t (size_t and uintptr_t don't have to be the same type). The signeds ensure one of them will be ptrdiff_t too. Change-Id: I9671dee8ceb64aa9b9cafffd17415a0bfcbd68b7 Reviewed-by: Lars Knoll (cherry picked from commit 85c69f023fe281b7f16e1a93e61be4432f7fef9b) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qmath.h | 10 ++++++++++ src/corelib/tools/qhash.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qmath.h b/src/corelib/kernel/qmath.h index b1e5b4f17e4..72057ee16d7 100644 --- a/src/corelib/kernel/qmath.h +++ b/src/corelib/kernel/qmath.h @@ -370,6 +370,16 @@ constexpr inline quint64 qNextPowerOfTwo(qint64 v) return qNextPowerOfTwo(quint64(v)); } +constexpr inline unsigned long qNextPowerOfTwo(unsigned long v) +{ + return qNextPowerOfTwo(QIntegerForSizeof::Unsigned(v)); +} + +constexpr inline unsigned long qNextPowerOfTwo(long v) +{ + return qNextPowerOfTwo(QIntegerForSizeof::Unsigned(v)); +} + QT_END_NAMESPACE #endif // QMATH_H diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index eedb594e265..b6a12a721e9 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -435,7 +435,7 @@ inline constexpr size_t bucketsForCapacity(size_t requestedCapacity) noexcept return SpanConstants::NEntries; if (requestedCapacity >= maxNumBuckets()) return maxNumBuckets(); - return qNextPowerOfTwo(QIntegerForSize::Unsigned(2 * requestedCapacity - 1)); + return qNextPowerOfTwo(2 * requestedCapacity - 1); } inline constexpr size_t bucketForHash(size_t nBuckets, size_t hash) noexcept {