refs #687, use hash to avoid unnecessary operations

* for bookings
* VATSIM file (plus check if cache really changed before writing)
* METARs
This commit is contained in:
Klaus Basan
2016-06-25 02:31:28 +02:00
parent 0253da8bf9
commit 0fca9c1f18
5 changed files with 73 additions and 22 deletions

View File

@@ -85,17 +85,33 @@ namespace BlackCore
void CThreadedReader::setInterval(int updatePeriodMs)
{
Q_ASSERT(this->m_updateTimer);
bool s;
if (updatePeriodMs < 1)
QTimer::singleShot(0, this, [this, updatePeriodMs]
{
s = QMetaObject::invokeMethod(m_updateTimer, "stop");
}
else
QWriteLocker wl(&this->m_lock);
if (updatePeriodMs < 1)
{
this->m_updateTimer->stop();
}
else {
this->m_updateTimer->start(updatePeriodMs);
}
});
}
bool CThreadedReader::didContentChange(const QString &content, int startPosition)
{
uint oldHash = 0;
{
s = QMetaObject::invokeMethod(m_updateTimer, "start", Q_ARG(int, updatePeriodMs));
QReadLocker rl(&this->m_lock);
oldHash = this->m_contentHash;
}
Q_ASSERT_X(s, Q_FUNC_INFO, "Failed invoke");
Q_UNUSED(s);
uint newHash = qHash(startPosition < 0 ? content : content.mid(startPosition));
if (oldHash == newHash) { return false; }
{
QWriteLocker wl(&this->m_lock);
this->m_contentHash = newHash;
}
return true;
}
void CThreadedReader::ps_toggleInterval()