mirror of
https://invent.kde.org/graphics/okular
synced 2024-09-13 13:11:41 +00:00
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:
parent
a6fc833662
commit
1479a6d28c
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue