summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-09-24 13:33:35 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-09-29 08:52:52 +0200
commit92e108bff83ac92b2fa2cc2bb77c2501e259814f (patch)
treecdf688087b241294550a85cdac90ac8aad9bc071 /src
parentcf0f1e08600edd508969d0f76c9dee49d469b7b3 (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qcache.h34
-rw-r--r--src/corelib/tools/qcache.qdoc14
2 files changed, 24 insertions, 24 deletions
diff --git a/src/corelib/tools/qcache.h b/src/corelib/tools/qcache.h
index fbfa2ab997..c8de12af60 100644
--- a/src/corelib/tools/qcache.h
+++ b/src/corelib/tools/qcache.h
@@ -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);
diff --git a/src/corelib/tools/qcache.qdoc b/src/corelib/tools/qcache.qdoc
index ffc21318f4..f9b1ffa8f4 100644
--- a/src/corelib/tools/qcache.qdoc
+++ b/src/corelib/tools/qcache.qdoc
@@ -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