summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoão Abecasis <joao@trolltech.com>2010-01-13 17:03:52 (GMT)
committerJoão Abecasis <joao@trolltech.com>2010-01-18 14:17:26 (GMT)
commitc7b3f408f772d565666910cb4495a7057796b648 (patch)
treef0a794f084b40b9ba33241dbd095bac4bb8ba1ef /src
parent2f6459ff25a59e913b5695dcd8919ead8d58947c (diff)
downloadQt-c7b3f408f772d565666910cb4495a7057796b648.zip
Qt-c7b3f408f772d565666910cb4495a7057796b648.tar.gz
Qt-c7b3f408f772d565666910cb4495a7057796b648.tar.bz2
QFile: Fix a pre-mature pessimization
Don't repeatedly call the fileEngine virtual function. Instead re-use the private data member if we know it has been filled. Reviewed-by: Markus Goetz
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qfile.cpp86
1 files changed, 42 insertions, 44 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp
index 4c7f3f0..7405339 100644
--- a/src/corelib/io/qfile.cpp
+++ b/src/corelib/io/qfile.cpp
@@ -650,7 +650,7 @@ QFile::remove()
unsetError();
return true;
}
- d->setError(QFile::RemoveError, fileEngine()->errorString());
+ d->setError(QFile::RemoveError, d->fileEngine->errorString());
}
return false;
}
@@ -704,7 +704,7 @@ QFile::rename(const QString &newName)
if (fileEngine()->rename(newName)) {
unsetError();
// engine was able to handle the new name so we just reset it
- fileEngine()->setFileName(newName);
+ d->fileEngine->setFileName(newName);
d->fileName = newName;
return true;
}
@@ -740,7 +740,7 @@ QFile::rename(const QString &newName)
if (error) {
out.remove();
} else {
- fileEngine()->setFileName(newName);
+ d->fileEngine->setFileName(newName);
setPermissions(permissions());
unsetError();
setFileName(newName);
@@ -805,7 +805,7 @@ QFile::link(const QString &linkName)
unsetError();
return true;
}
- d->setError(QFile::RenameError, fileEngine()->errorString());
+ d->setError(QFile::RenameError, d->fileEngine->errorString());
return false;
}
@@ -994,10 +994,10 @@ bool QFile::open(OpenMode mode)
seek(size());
return true;
}
- QFile::FileError err = fileEngine()->error();
+ QFile::FileError err = d->fileEngine->error();
if(err == QFile::UnspecifiedError)
err = QFile::OpenError;
- d->setError(err, fileEngine()->errorString());
+ d->setError(err, d->fileEngine->errorString());
return false;
}
@@ -1155,8 +1155,8 @@ QFile::handle() const
if (!isOpen())
return -1;
- if (QAbstractFileEngine *engine = fileEngine())
- return engine->handle();
+ if (fileEngine())
+ return d->fileEngine->handle();
return -1;
}
@@ -1189,13 +1189,12 @@ QFile::handle() const
uchar *QFile::map(qint64 offset, qint64 size, MemoryMapFlags flags)
{
Q_D(QFile);
- QAbstractFileEngine *engine = fileEngine();
- if (engine
- && engine->supportsExtension(QAbstractFileEngine::MapExtension)) {
+ if (fileEngine()
+ && d->fileEngine->supportsExtension(QAbstractFileEngine::MapExtension)) {
unsetError();
- uchar *address = engine->map(offset, size, flags);
+ uchar *address = d->fileEngine->map(offset, size, flags);
if (address == 0)
- d->setError(engine->error(), engine->errorString());
+ d->setError(d->fileEngine->error(), d->fileEngine->errorString());
return address;
}
return 0;
@@ -1212,13 +1211,12 @@ uchar *QFile::map(qint64 offset, qint64 size, MemoryMapFlags flags)
bool QFile::unmap(uchar *address)
{
Q_D(QFile);
- QAbstractFileEngine *engine = fileEngine();
- if (engine
- && engine->supportsExtension(QAbstractFileEngine::UnMapExtension)) {
+ if (fileEngine()
+ && d->fileEngine->supportsExtension(QAbstractFileEngine::UnMapExtension)) {
unsetError();
- bool success = engine->unmap(address);
+ bool success = d->fileEngine->unmap(address);
if (!success)
- d->setError(engine->error(), engine->errorString());
+ d->setError(d->fileEngine->error(), d->fileEngine->errorString());
return success;
}
return false;
@@ -1251,13 +1249,14 @@ QFile::resize(qint64 sz)
Q_D(QFile);
if (!d->ensureFlushed())
return false;
- if (isOpen() && fileEngine()->pos() > sz)
+ fileEngine();
+ if (isOpen() && d->fileEngine->pos() > sz)
seek(sz);
- if(fileEngine()->setSize(sz)) {
+ if(d->fileEngine->setSize(sz)) {
unsetError();
return true;
}
- d->setError(QFile::ResizeError, fileEngine()->errorString());
+ d->setError(QFile::ResizeError, d->fileEngine->errorString());
return false;
}
@@ -1321,7 +1320,7 @@ QFile::setPermissions(Permissions permissions)
unsetError();
return true;
}
- d->setError(QFile::PermissionsError, fileEngine()->errorString());
+ d->setError(QFile::PermissionsError, d->fileEngine->errorString());
return false;
}
@@ -1354,23 +1353,23 @@ bool
QFile::flush()
{
Q_D(QFile);
+ fileEngine();
if (!d->writeBuffer.isEmpty()) {
qint64 size = d->writeBuffer.size();
- if (_qfile_writeData(d->fileEngine ? d->fileEngine : fileEngine(),
- &d->writeBuffer) != size) {
- QFile::FileError err = fileEngine()->error();
+ if (_qfile_writeData(d->fileEngine, &d->writeBuffer) != size) {
+ QFile::FileError err = d->fileEngine->error();
if(err == QFile::UnspecifiedError)
err = QFile::WriteError;
- d->setError(err, fileEngine()->errorString());
+ d->setError(err, d->fileEngine->errorString());
return false;
}
}
- if (!fileEngine()->flush()) {
- QFile::FileError err = fileEngine()->error();
+ if (!d->fileEngine->flush()) {
+ QFile::FileError err = d->fileEngine->error();
if(err == QFile::UnspecifiedError)
err = QFile::WriteError;
- d->setError(err, fileEngine()->errorString());
+ d->setError(err, d->fileEngine->errorString());
return false;
}
return true;
@@ -1398,7 +1397,7 @@ QFile::close()
if (fileEngine()->close() && flushed)
unsetError();
else if (flushed)
- d->setError(fileEngine()->error(), fileEngine()->errorString());
+ d->setError(d->fileEngine->error(), d->fileEngine->errorString());
}
/*!
@@ -1451,10 +1450,10 @@ bool QFile::atEnd() const
return false;
// If the file engine knows best, say what it says.
- if (fileEngine()->supportsExtension(QAbstractFileEngine::AtEndExtension)) {
+ if (d->fileEngine->supportsExtension(QAbstractFileEngine::AtEndExtension)) {
// Check if the file engine supports AtEndExtension, and if it does,
// check if the file engine claims to be at the end.
- return fileEngine()->atEnd();
+ return d->fileEngine->atEnd();
}
// Fall back to checking how much is available (will stat files).
@@ -1476,11 +1475,11 @@ bool QFile::seek(qint64 off)
if (!d->ensureFlushed())
return false;
- if (!fileEngine()->seek(off) || !QIODevice::seek(off)) {
- QFile::FileError err = fileEngine()->error();
+ if (!d->fileEngine->seek(off) || !QIODevice::seek(off)) {
+ QFile::FileError err = d->fileEngine->error();
if(err == QFile::UnspecifiedError)
err = QFile::PositionError;
- d->setError(err, fileEngine()->errorString());
+ d->setError(err, d->fileEngine->errorString());
return false;
}
unsetError();
@@ -1496,8 +1495,8 @@ qint64 QFile::readLineData(char *data, qint64 maxlen)
if (!d->ensureFlushed())
return -1;
- if (fileEngine()->supportsExtension(QAbstractFileEngine::FastReadLineExtension))
- return fileEngine()->readLine(data, maxlen);
+ if (d->fileEngine->supportsExtension(QAbstractFileEngine::FastReadLineExtension))
+ return d->fileEngine->readLine(data, maxlen);
// Fall back to QIODevice's readLine implementation if the engine
// cannot do it faster.
@@ -1516,15 +1515,15 @@ qint64 QFile::readData(char *data, qint64 len)
return -1;
qint64 ret = -1;
- qint64 read = fileEngine()->read(data, len);
+ qint64 read = d->fileEngine->read(data, len);
if (read != -1)
ret = read;
if(ret < 0) {
- QFile::FileError err = fileEngine()->error();
+ QFile::FileError err = d->fileEngine->error();
if(err == QFile::UnspecifiedError)
err = QFile::ReadError;
- d->setError(err, fileEngine()->errorString());
+ d->setError(err, d->fileEngine->errorString());
}
return ret;
}
@@ -1606,13 +1605,12 @@ QFile::writeData(const char *data, qint64 len)
// Write directly to the engine if the block size is larger than
// the write buffer size.
if (!buffered || len > QFILE_WRITEBUFFER_SIZE) {
- QAbstractFileEngine *fe = d->fileEngine ? d->fileEngine : fileEngine();
- qint64 ret = fe->write(data, len);
+ qint64 ret = d->fileEngine->write(data, len);
if(ret < 0) {
- QFile::FileError err = fileEngine()->error();
+ QFile::FileError err = d->fileEngine->error();
if(err == QFile::UnspecifiedError)
err = QFile::WriteError;
- d->setError(err, fileEngine()->errorString());
+ d->setError(err, d->fileEngine->errorString());
}
return ret;
}