Small speed up patch, caches the value of getFreeMemory for 2 seconds,

that reduces the access of /proc/meminfo.

svn path=/trunk/playground/graphics/okular/; revision=605189
This commit is contained in:
Tobias Koenig 2006-11-15 19:39:39 +00:00
parent a6fc833662
commit 1479a6d28c

View file

@ -1642,6 +1642,12 @@ int Document::getTotalMemory()
int Document::getFreeMemory()
{
static QTime lastUpdate = QTime::currentTime();
static int cachedValue = 0;
if ( lastUpdate.secsTo( QTime::currentTime() ) <= 2 )
return cachedValue;
#ifdef __linux__
// if /proc/meminfo doesn't exist, return MEMORY FULL
QFile memFile( "/proc/meminfo" );
@ -1665,7 +1671,10 @@ int Document::getFreeMemory()
memoryFree -= entry.section( ' ', -2, -2 ).toInt();
}
memFile.close();
return 1024 * memoryFree;
lastUpdate = QTime::currentTime();
return ( cachedValue = (1024 * memoryFree) );
#else
// tell the memory is full.. will act as in LOW profile
return 0;