mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 04:49:47 -07:00
Avoid redundant hashing
The return type of `std::hash()` is larger (or equal) than what `qHash()` requires so we can omit hashing it again.
This commit is contained in:
parent
926d51839f
commit
b3fb6bd990
3 changed files with 14 additions and 14 deletions
|
@ -96,7 +96,7 @@ std::size_t BitTorrent::qHash(const BitTorrent::TorrentID &key, const std::size_
|
||||||
uint BitTorrent::qHash(const BitTorrent::TorrentID &key, const uint seed)
|
uint BitTorrent::qHash(const BitTorrent::TorrentID &key, const uint seed)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
return ::qHash(std::hash<TorrentID::UnderlyingType>()(key), seed);
|
return ::qHash(static_cast<TorrentID::BaseType>(key), seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BitTorrent::operator==(const BitTorrent::InfoHash &left, const BitTorrent::InfoHash &right)
|
bool BitTorrent::operator==(const BitTorrent::InfoHash &left, const BitTorrent::InfoHash &right)
|
||||||
|
|
|
@ -28,28 +28,24 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <libtorrent/units.hpp>
|
#include <libtorrent/units.hpp>
|
||||||
|
|
||||||
#include <QtGlobal>
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
|
||||||
// From https://doc.qt.io/qt-6/qhash.html#the-hashing-function:
|
|
||||||
// A hashing function for a key type K may be provided in two different ways.
|
|
||||||
// The first way is by having an overload of qHash() in K's namespace.
|
|
||||||
namespace libtorrent
|
namespace libtorrent
|
||||||
{
|
{
|
||||||
namespace aux
|
namespace aux
|
||||||
{
|
{
|
||||||
template <typename T, typename Tag>
|
template <typename T, typename Tag>
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
|
||||||
std::size_t qHash(const strong_typedef<T, Tag> &key, const std::size_t seed = 0)
|
|
||||||
#else
|
|
||||||
uint qHash(const strong_typedef<T, Tag> &key, const uint seed = 0)
|
uint qHash(const strong_typedef<T, Tag> &key, const uint seed = 0)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
return ::qHash((std::hash<strong_typedef<T, Tag>> {})(key), seed);
|
return ::qHash((std::hash<strong_typedef<T, Tag>> {})(key), seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -131,12 +131,16 @@ bool operator<(const Digest32<N> &left, const Digest32<N> &right)
|
||||||
< static_cast<typename Digest32<N>::UnderlyingType>(right);
|
< static_cast<typename Digest32<N>::UnderlyingType>(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <int N>
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||||
|
template <int N>
|
||||||
std::size_t qHash(const Digest32<N> &key, const std::size_t seed = 0)
|
std::size_t qHash(const Digest32<N> &key, const std::size_t seed = 0)
|
||||||
#else
|
|
||||||
uint qHash(const Digest32<N> &key, const uint seed = 0)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
return ::qHash(std::hash<typename Digest32<N>::UnderlyingType>()(key), seed);
|
return ::qHash(static_cast<typename Digest32<N>::UnderlyingType>(key), seed);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
template <int N>
|
||||||
|
uint qHash(const Digest32<N> &key, const uint seed = 0)
|
||||||
|
{
|
||||||
|
return static_cast<uint>((std::hash<typename Digest32<N>::UnderlyingType> {})(key)) ^ seed;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue