Kstars

pixcache.cpp
1/*
2 SPDX-FileCopyrightText: 2015-2017 Pavel Mraz
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "pixcache.h"
8
9static int qHash(const pixCacheKey_t &key, uint seed)
10{
11 return qHash(QString("%1_%2_%3").arg(key.level).arg(key.pix).arg(key.uid), seed);
12}
13
14inline bool operator<(const pixCacheKey_t &k1, const pixCacheKey_t &k2)
15{
16 if (k1.uid != k2.uid)
17 {
18 return k1.uid < k2.uid;
19 }
20
21 if (k1.level != k2.level)
22 {
23 return k1.level < k2.level;
24 }
25
26 return k1.pix < k2.pix;
27}
28
29inline bool operator==(const pixCacheKey_t &k1, const pixCacheKey_t &k2)
30{
31 return (k1.uid == k2.uid) && (k1.level == k2.level) && (k1.pix == k2.pix);
32}
33
34void PixCache::add(pixCacheKey_t &key, pixCacheItem_t *item, int cost)
35{
36 Q_ASSERT(cost < m_cache.maxCost());
37
38 m_cache.insert(key, item, cost);
39}
40
41pixCacheItem_t *PixCache::get(pixCacheKey_t &key)
42{
43 return m_cache.object(key);
44}
45
46void PixCache::setMaxCost(int maxCost)
47{
48 m_cache.setMaxCost(maxCost);
49}
50
51void PixCache::printCache()
52{
53 qDebug() << Q_FUNC_INFO << " -- cache ---------------";
54 qDebug() << Q_FUNC_INFO << m_cache.size() << m_cache.totalCost() << m_cache.maxCost();
55}
56
57int PixCache::used()
58{
59 return m_cache.totalCost();
60}
KTEXTEDITOR_EXPORT size_t qHash(KTextEditor::Cursor cursor, size_t seed=0) noexcept
bool operator<(const PosRange< Trait > &l, const PosRange< Trait > &r)
bool operator==(const StyleDelim &l, const StyleDelim &r)
bool insert(const Key &key, T *object, qsizetype cost)
qsizetype maxCost() const const
T * object(const Key &key) const const
void setMaxCost(qsizetype cost)
qsizetype size() const const
qsizetype totalCost() const const
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.