Commit 4455c2a5 authored by Jekyll Wu's avatar Jekyll Wu
Browse files

Rename member variable fileMap and readWriteBalance.

parent 31ba6915
......@@ -87,7 +87,7 @@ FIXME: There is noticeable decrease in speed, also. Perhaps,
HistoryFile::HistoryFile()
: _fd(-1),
_length(0),
fileMap(0)
_fileMap(0)
{
if (_tmpFile.open())
{
......@@ -98,7 +98,7 @@ HistoryFile::HistoryFile()
HistoryFile::~HistoryFile()
{
if (fileMap)
if (_fileMap)
unmap();
}
......@@ -107,38 +107,38 @@ HistoryFile::~HistoryFile()
//to avoid this.
void HistoryFile::map()
{
assert( fileMap == 0 );
assert( _fileMap == 0 );
fileMap = (char*)mmap( 0 , _length , PROT_READ , MAP_PRIVATE , _fd , 0 );
_fileMap = (char*)mmap( 0 , _length , PROT_READ , MAP_PRIVATE , _fd , 0 );
//if mmap'ing fails, fall back to the read-lseek combination
if ( fileMap == MAP_FAILED )
if ( _fileMap == MAP_FAILED )
{
readWriteBalance = 0;
fileMap = 0;
_readWriteBalance = 0;
_fileMap = 0;
kWarning() << k_funcinfo << ": mmap'ing history failed. errno = " << errno;
}
}
void HistoryFile::unmap()
{
int result = munmap( fileMap , _length );
int result = munmap( _fileMap , _length );
assert( result == 0 ); Q_UNUSED( result );
fileMap = 0;
_fileMap = 0;
}
bool HistoryFile::isMapped()
{
return (fileMap != 0);
return (_fileMap != 0);
}
void HistoryFile::add(const unsigned char* bytes, int len)
{
if ( fileMap )
if ( _fileMap )
unmap();
readWriteBalance++;
_readWriteBalance++;
int rc = 0;
......@@ -153,14 +153,14 @@ void HistoryFile::get(unsigned char* bytes, int len, int loc)
//If there are many more get() calls compared with add()
//calls (decided by using MAP_THRESHOLD) then mmap the log
//file to improve performance.
readWriteBalance--;
if ( !fileMap && readWriteBalance < MAP_THRESHOLD )
_readWriteBalance--;
if ( !_fileMap && _readWriteBalance < MAP_THRESHOLD )
map();
if ( fileMap )
if ( _fileMap )
{
for (int i=0;i<len;i++)
bytes[i]=fileMap[loc+i];
bytes[i]=_fileMap[loc+i];
}
else
{
......
......@@ -68,15 +68,15 @@ private:
KTemporaryFile _tmpFile;
//pointer to start of mmap'ed file data, or 0 if the file is not mmap'ed
char* fileMap;
char* _fileMap;
//incremented whenver 'add' is called and decremented whenever
//'get' is called.
//this is used to detect when a large number of lines are being read and processed from the history
//and automatically mmap the file for better performance (saves the overhead of many lseek-read calls).
int readWriteBalance;
int _readWriteBalance;
//when readWriteBalance goes below this threshold, the file will be mmap'ed automatically
//when _readWriteBalance goes below this threshold, the file will be mmap'ed automatically
static const int MAP_THRESHOLD = -1000;
};
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment