apply suggested changes

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-11-06 10:51:34 +02:00
parent 710a48fcaf
commit cc291219f9
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318

View File

@ -101,10 +101,14 @@ class PixmapCache final : public QObject {
*/ */
bool _markCacheMissByEviciton() bool _markCacheMissByEviciton()
{ {
static constexpr int maxInt = std::numeric_limits<int>::max();
static constexpr uint oneMB = 1000;
static constexpr int oneSecond = 1000;
auto now = QTime::currentTime(); auto now = QTime::currentTime();
if (!m_last_cache_miss_by_eviciton.isNull()) { if (!m_last_cache_miss_by_eviciton.isNull()) {
auto diff = m_last_cache_miss_by_eviciton.msecsTo(now); auto diff = m_last_cache_miss_by_eviciton.msecsTo(now);
if (diff < 1000) { // less than a second ago if (diff < oneSecond) { // less than a second ago
++m_consecutive_fast_evicitons; ++m_consecutive_fast_evicitons;
} else { } else {
m_consecutive_fast_evicitons = 0; m_consecutive_fast_evicitons = 0;
@ -112,10 +116,10 @@ class PixmapCache final : public QObject {
} }
m_last_cache_miss_by_eviciton = now; m_last_cache_miss_by_eviciton = now;
if (m_consecutive_fast_evicitons >= m_consecutive_fast_evicitons_threshold) { if (m_consecutive_fast_evicitons >= m_consecutive_fast_evicitons_threshold) {
// double the cache size // increase the cache size
auto newSize = _cacheLimit() * 2ll; uint newSize = _cacheLimit() + oneMB;
if (newSize >= std::numeric_limits<int>::max()) { // double it until you overflow :D if (newSize >= maxInt) { // increase it until you overflow :D
newSize = std::numeric_limits<int>::max(); newSize = maxInt;
qDebug() << m_consecutive_fast_evicitons qDebug() << m_consecutive_fast_evicitons
<< tr("pixmap cache misses by eviction happened too fast, doing nothing as the cache size reached it's limit"); << tr("pixmap cache misses by eviction happened too fast, doing nothing as the cache size reached it's limit");
} else { } else {