diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2010-08-09 11:02:33 (GMT) |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2010-08-09 17:45:26 (GMT) |
commit | 9a3e7c9c32167b777a090ee13082323d10895694 (patch) | |
tree | b102cb2dca1feafd45af99787463427b4498601e /src | |
parent | 2e7d5def1fdabb5949fbffc629da500aa2bb78d7 (diff) | |
download | Qt-9a3e7c9c32167b777a090ee13082323d10895694.zip Qt-9a3e7c9c32167b777a090ee13082323d10895694.tar.gz Qt-9a3e7c9c32167b777a090ee13082323d10895694.tar.bz2 |
Fix minor premature pessimizations in file engine creation
QAbstractFileEngineHandler ctor adds itself once to handler list, dtor
should not try to be any smarter.
Repeatedly calling the global static "constructor" fileEngineHandlers()
could lead to additional overhead while checking for repeated
construction -- that said, compilers can probably figure this one out,
but being explicit shouldn't hurt.
Reduce string manipulation and copying. Also, prefer QStringBuilder to
building strings by hand.
Reviewed-by: Marius Storm-Olsen
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qabstractfileengine.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/corelib/io/qabstractfileengine.cpp b/src/corelib/io/qabstractfileengine.cpp index 75eaeb4..80bc244 100644 --- a/src/corelib/io/qabstractfileengine.cpp +++ b/src/corelib/io/qabstractfileengine.cpp @@ -50,6 +50,7 @@ // built-in handlers #include "qfsfileengine.h" #include "qdiriterator.h" +#include "qstringbuilder.h" QT_BEGIN_NAMESPACE @@ -138,7 +139,7 @@ QAbstractFileEngineHandler::~QAbstractFileEngineHandler() QWriteLocker locker(fileEngineHandlerMutex()); // Remove this handler from the handler list only if the list is valid. if (!qt_abstractfileenginehandlerlist_shutDown) - fileEngineHandlers()->removeAll(this); + fileEngineHandlers()->removeOne(this); } /*! @@ -173,8 +174,9 @@ QAbstractFileEngine *QAbstractFileEngine::create(const QString &fileName) QReadLocker locker(fileEngineHandlerMutex()); // check for registered handlers that can load the file - for (int i = 0; i < fileEngineHandlers()->size(); i++) { - if (QAbstractFileEngine *ret = fileEngineHandlers()->at(i)->create(fileName)) + QAbstractFileEngineHandlerList *handlers = fileEngineHandlers(); + for (int i = 0; i < handlers->size(); i++) { + if (QAbstractFileEngine *ret = handlers->at(i)->create(fileName)) return ret; } } @@ -185,13 +187,9 @@ QAbstractFileEngine *QAbstractFileEngine::create(const QString &fileName) if (prefixSeparator == 0) { return new QResourceFileEngine(fileName); } else if (prefixSeparator > 1) { - QString prefix = fileName.left(prefixSeparator); - QString fileNameWithoutPrefix = fileName.mid(prefixSeparator + 1).prepend(QLatin1Char('/')); - const QStringList &paths = QDir::searchPaths(prefix); + const QStringList &paths = QDir::searchPaths(fileName.left(prefixSeparator)); for (int i = 0; i < paths.count(); i++) { - QString path = paths.at(i); - path.append(fileNameWithoutPrefix); - QAbstractFileEngine *engine = create(path); + QAbstractFileEngine *engine = create(paths.at(i) % QLatin1Char('/') % fileName.mid(prefixSeparator + 1)); if (engine && (engine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::ExistsFlag)) { return engine; } |