Switch QCache costs to qsizetype
Since size is already qsizetype and costs is multipla of size, it seems costs should be qsizetype as well. Change-Id: Iae85baaba5842460358e369a666fef6ebb7e52b4 Reviewed-by: Lars Knoll <lars.knoll@qt.io>bb10
parent
cf0f1e0860
commit
92e108bff8
|
|
@ -50,9 +50,9 @@ class QCache
|
|||
{
|
||||
struct Value {
|
||||
T *t = nullptr;
|
||||
int cost = 0;
|
||||
qsizetype cost = 0;
|
||||
Value() noexcept = default;
|
||||
Value(T *tt, int c) noexcept
|
||||
Value(T *tt, qsizetype c) noexcept
|
||||
: t(tt), cost(c)
|
||||
{}
|
||||
Value(Value &&other) noexcept
|
||||
|
|
@ -99,11 +99,11 @@ class QCache
|
|||
value(std::move(t))
|
||||
{
|
||||
}
|
||||
static void createInPlace(Node *n, const Key &k, T *o, int cost)
|
||||
static void createInPlace(Node *n, const Key &k, T *o, qsizetype cost)
|
||||
{
|
||||
new (n) Node{ Key(k), Value(o, cost) };
|
||||
}
|
||||
void emplace(T *o, int cost)
|
||||
void emplace(T *o, qsizetype cost)
|
||||
{
|
||||
value = Value(o, cost);
|
||||
}
|
||||
|
|
@ -143,8 +143,8 @@ class QCache
|
|||
|
||||
mutable Chain chain;
|
||||
Data d;
|
||||
int mx = 0;
|
||||
int total = 0;
|
||||
qsizetype mx = 0;
|
||||
qsizetype total = 0;
|
||||
|
||||
void unlink(Node *n) noexcept(std::is_nothrow_destructible_v<Node>)
|
||||
{
|
||||
|
|
@ -175,7 +175,7 @@ class QCache
|
|||
return n->value.t;
|
||||
}
|
||||
|
||||
void trim(int m) noexcept(std::is_nothrow_destructible_v<Node>)
|
||||
void trim(qsizetype m) noexcept(std::is_nothrow_destructible_v<Node>)
|
||||
{
|
||||
Chain *n = chain.prev;
|
||||
while (n != &chain && total > m) {
|
||||
|
|
@ -189,31 +189,31 @@ class QCache
|
|||
Q_DISABLE_COPY(QCache)
|
||||
|
||||
public:
|
||||
inline explicit QCache(int maxCost = 100) noexcept
|
||||
inline explicit QCache(qsizetype maxCost = 100) noexcept
|
||||
: mx(maxCost)
|
||||
{}
|
||||
inline ~QCache() { clear(); }
|
||||
|
||||
inline int maxCost() const noexcept { return mx; }
|
||||
void setMaxCost(int m) noexcept(std::is_nothrow_destructible_v<Node>)
|
||||
inline qsizetype maxCost() const noexcept { return mx; }
|
||||
void setMaxCost(qsizetype m) noexcept(std::is_nothrow_destructible_v<Node>)
|
||||
{
|
||||
mx = m;
|
||||
trim(mx);
|
||||
}
|
||||
inline int totalCost() const noexcept { return total; }
|
||||
inline qsizetype totalCost() const noexcept { return total; }
|
||||
|
||||
inline qsizetype size() const noexcept { return d.size; }
|
||||
inline qsizetype count() const noexcept { return d.size; }
|
||||
inline qsizetype size() const noexcept { return qsizetype(d.size); }
|
||||
inline qsizetype count() const noexcept { return qsizetype(d.size); }
|
||||
inline bool isEmpty() const noexcept { return !d.size; }
|
||||
inline QList<Key> keys() const
|
||||
{
|
||||
QList<Key> k;
|
||||
if (d.size) {
|
||||
k.reserve(typename QList<Key>::size_type(d.size));
|
||||
if (size()) {
|
||||
k.reserve(size());
|
||||
for (auto it = d.begin(); it != d.end(); ++it)
|
||||
k << it.node()->key;
|
||||
}
|
||||
Q_ASSERT(k.size() == qsizetype(d.size));
|
||||
Q_ASSERT(k.size() == size());
|
||||
return k;
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ public:
|
|||
chain.prev = &chain;
|
||||
}
|
||||
|
||||
bool insert(const Key &key, T *object, int cost = 1)
|
||||
bool insert(const Key &key, T *object, qsizetype cost = 1)
|
||||
{
|
||||
remove(key);
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@
|
|||
\sa QPixmapCache, QHash, QMap
|
||||
*/
|
||||
|
||||
/*! \fn template <class Key, class T> QCache<Key, T>::QCache(int maxCost = 100)
|
||||
/*! \fn template <class Key, class T> QCache<Key, T>::QCache(qsizetype maxCost = 100)
|
||||
|
||||
Constructs a cache whose contents will never have a total cost
|
||||
greater than \a maxCost.
|
||||
|
|
@ -91,14 +91,14 @@
|
|||
Destroys the cache. Deletes all the objects in the cache.
|
||||
*/
|
||||
|
||||
/*! \fn template <class Key, class T> int QCache<Key, T>::maxCost() const
|
||||
/*! \fn template <class Key, class T> qsizetype QCache<Key, T>::maxCost() const
|
||||
|
||||
Returns the maximum allowed total cost of the cache.
|
||||
|
||||
\sa setMaxCost(), totalCost()
|
||||
*/
|
||||
|
||||
/*! \fn template <class Key, class T> void QCache<Key, T>::setMaxCost(int cost)
|
||||
/*! \fn template <class Key, class T> void QCache<Key, T>::setMaxCost(qsizetype cost)
|
||||
|
||||
Sets the maximum allowed total cost of the cache to \a cost. If
|
||||
the current total cost is greater than \a cost, some objects are
|
||||
|
|
@ -107,7 +107,7 @@
|
|||
\sa maxCost(), totalCost()
|
||||
*/
|
||||
|
||||
/*! \fn template <class Key, class T> int QCache<Key, T>::totalCost() const
|
||||
/*! \fn template <class Key, class T> qsizetype QCache<Key, T>::totalCost() const
|
||||
|
||||
Returns the total cost of the objects in the cache.
|
||||
|
||||
|
|
@ -120,14 +120,14 @@
|
|||
\sa setMaxCost()
|
||||
*/
|
||||
|
||||
/*! \fn template <class Key, class T> int QCache<Key, T>::size() const
|
||||
/*! \fn template <class Key, class T> qsizetype QCache<Key, T>::size() const
|
||||
|
||||
Returns the number of objects in the cache.
|
||||
|
||||
\sa isEmpty()
|
||||
*/
|
||||
|
||||
/*! \fn template <class Key, class T> int QCache<Key, T>::count() const
|
||||
/*! \fn template <class Key, class T> qsizetype QCache<Key, T>::count() const
|
||||
|
||||
Same as size().
|
||||
*/
|
||||
|
|
@ -153,7 +153,7 @@
|
|||
*/
|
||||
|
||||
|
||||
/*! \fn template <class Key, class T> bool QCache<Key, T>::insert(const Key &key, T *object, int cost = 1)
|
||||
/*! \fn template <class Key, class T> bool QCache<Key, T>::insert(const Key &key, T *object, qsizetype cost = 1)
|
||||
|
||||
Inserts \a object into the cache with key \a key and
|
||||
associated cost \a cost. Any object with the same key already in
|
||||
|
|
|
|||
Loading…
Reference in New Issue