QCryptographicHash: constexpr ALL of QSmallByteArray
... because we can. Pick-to: 6.5 Change-Id: I03872a69ac4625ca73b0a7f0310a2a951615b000 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
c513d4fe31
commit
29b55dcb83
@ -132,19 +132,19 @@ public:
|
|||||||
QSmallByteArray() = default;
|
QSmallByteArray() = default;
|
||||||
// all compiler-generated SMFs are ok!
|
// all compiler-generated SMFs are ok!
|
||||||
template <std::size_t M, std::enable_if_t<M < N, bool> = true> // M == N is for copy ctor!
|
template <std::size_t M, std::enable_if_t<M < N, bool> = true> // M == N is for copy ctor!
|
||||||
QSmallByteArray(const QSmallByteArray<M> &other) noexcept
|
constexpr QSmallByteArray(const QSmallByteArray<M> &other) noexcept
|
||||||
{
|
{
|
||||||
assign(other);
|
assign(other);
|
||||||
}
|
}
|
||||||
template <std::size_t M, std::enable_if_t<M < N, bool> = true> // M == N is for copy-assignment op!
|
template <std::size_t M, std::enable_if_t<M < N, bool> = true> // M == N is for copy-assignment op!
|
||||||
QSmallByteArray &operator=(const QSmallByteArray<M> &other) noexcept
|
constexpr QSmallByteArray &operator=(const QSmallByteArray<M> &other) noexcept
|
||||||
{
|
{
|
||||||
assign(other);
|
assign(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Container> // ### underconstrained
|
template <typename Container> // ### underconstrained
|
||||||
void assign(const Container &c)
|
constexpr void assign(const Container &c)
|
||||||
{
|
{
|
||||||
const size_t otherSize = size_t(std::size(c));
|
const size_t otherSize = size_t(std::size(c));
|
||||||
Q_ASSERT(otherSize < N);
|
Q_ASSERT(otherSize < N);
|
||||||
@ -152,43 +152,43 @@ public:
|
|||||||
m_size = quint8(otherSize);
|
m_size = quint8(otherSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
quint8 *data() noexcept { return m_data.data(); }
|
constexpr quint8 *data() noexcept { return m_data.data(); }
|
||||||
const quint8 *data() const noexcept { return m_data.data(); }
|
constexpr const quint8 *data() const noexcept { return m_data.data(); }
|
||||||
qsizetype size() const noexcept { return qsizetype{m_size}; }
|
constexpr qsizetype size() const noexcept { return qsizetype{m_size}; }
|
||||||
quint8 &operator[](qsizetype n)
|
constexpr quint8 &operator[](qsizetype n)
|
||||||
{
|
{
|
||||||
Q_ASSERT(n < size());
|
Q_ASSERT(n < size());
|
||||||
return data()[n];
|
return data()[n];
|
||||||
}
|
}
|
||||||
const quint8 &operator[](qsizetype n) const
|
constexpr const quint8 &operator[](qsizetype n) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(n < size());
|
Q_ASSERT(n < size());
|
||||||
return data()[n];
|
return data()[n];
|
||||||
}
|
}
|
||||||
bool isEmpty() const noexcept { return size() == 0; }
|
constexpr bool isEmpty() const noexcept { return size() == 0; }
|
||||||
void clear() noexcept { m_size = 0; }
|
constexpr void clear() noexcept { m_size = 0; }
|
||||||
void resizeForOverwrite(qsizetype s)
|
constexpr void resizeForOverwrite(qsizetype s)
|
||||||
{
|
{
|
||||||
Q_ASSERT(s >= 0);
|
Q_ASSERT(s >= 0);
|
||||||
Q_ASSERT(size_t(s) <= N);
|
Q_ASSERT(size_t(s) <= N);
|
||||||
m_size = std::uint8_t(s);
|
m_size = std::uint8_t(s);
|
||||||
}
|
}
|
||||||
void resize(qsizetype s, quint8 v)
|
constexpr void resize(qsizetype s, quint8 v)
|
||||||
{
|
{
|
||||||
const auto oldSize = size();
|
const auto oldSize = size();
|
||||||
resizeForOverwrite(s);
|
resizeForOverwrite(s);
|
||||||
if (s > oldSize)
|
if (s > oldSize)
|
||||||
memset(data() + oldSize, v, size() - oldSize);
|
memset(data() + oldSize, v, size() - oldSize);
|
||||||
}
|
}
|
||||||
QByteArrayView toByteArrayView() const noexcept
|
constexpr QByteArrayView toByteArrayView() const noexcept
|
||||||
{ return *this; }
|
{ return *this; }
|
||||||
|
|
||||||
auto begin() noexcept { return data(); }
|
constexpr auto begin() noexcept { return data(); }
|
||||||
auto begin() const noexcept { return data(); }
|
constexpr auto begin() const noexcept { return data(); }
|
||||||
auto cbegin() const noexcept { return begin(); }
|
constexpr auto cbegin() const noexcept { return begin(); }
|
||||||
auto end() noexcept { return data() + size(); }
|
constexpr auto end() noexcept { return data() + size(); }
|
||||||
auto end() const noexcept { return data() + size(); }
|
constexpr auto end() const noexcept { return data() + size(); }
|
||||||
auto cend() const noexcept { return end(); }
|
constexpr auto cend() const noexcept { return end(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr int hashLengthInternal(QCryptographicHash::Algorithm method) noexcept
|
static constexpr int hashLengthInternal(QCryptographicHash::Algorithm method) noexcept
|
||||||
|
Loading…
x
Reference in New Issue
Block a user