summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qabstractfileengine.cpp
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2010-08-09 17:56:14 +0200
committerJoão Abecasis <joao.abecasis@nokia.com>2010-08-09 19:45:30 +0200
commit1aca3a1c6d104e52a15039cdbbe88a5e55c9235e (patch)
tree3af430693e8f4f6570b4aebda4a2af655a8c6af1 /src/corelib/io/qabstractfileengine.cpp
parent127cab437b53096b18beb0cfe299137dc384060d (diff)
Are custom file engines in use?
If no custom file engine handlers have been registered, we can avoid using the Read/Write lock and, most of the time, we also avoid the creating the handler list at all. Since the custom handler for QResource's engine has been folded into the default handler, there should be no other internal use of this API, thus triggering this optimization by default for all users. The new flag may also in the future be exported to other modules to trigger bypassing of file engines completely. Reviewed-by: Marius Storm-Olsen
Diffstat (limited to 'src/corelib/io/qabstractfileengine.cpp')
-rw-r--r--src/corelib/io/qabstractfileengine.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/corelib/io/qabstractfileengine.cpp b/src/corelib/io/qabstractfileengine.cpp
index 6646e4e7d7..37a093c513 100644
--- a/src/corelib/io/qabstractfileengine.cpp
+++ b/src/corelib/io/qabstractfileengine.cpp
@@ -98,6 +98,8 @@ QT_BEGIN_NAMESPACE
\sa QAbstractFileEngine, QAbstractFileEngine::create()
*/
+static bool qt_file_engine_handlers_in_use = false;
+
/*
All application-wide handlers are stored in this list. The mutex must be
acquired to ensure thread safety.
@@ -127,6 +129,7 @@ Q_GLOBAL_STATIC(QAbstractFileEngineHandlerList, fileEngineHandlers)
QAbstractFileEngineHandler::QAbstractFileEngineHandler()
{
QWriteLocker locker(fileEngineHandlerMutex());
+ qt_file_engine_handlers_in_use = true;
fileEngineHandlers()->prepend(this);
}
@@ -138,8 +141,12 @@ QAbstractFileEngineHandler::~QAbstractFileEngineHandler()
{
QWriteLocker locker(fileEngineHandlerMutex());
// Remove this handler from the handler list only if the list is valid.
- if (!qt_abstractfileenginehandlerlist_shutDown)
- fileEngineHandlers()->removeOne(this);
+ if (!qt_abstractfileenginehandlerlist_shutDown) {
+ QAbstractFileEngineHandlerList *handlers = fileEngineHandlers();
+ handlers->removeOne(this);
+ if (handlers->isEmpty())
+ qt_file_engine_handlers_in_use = false;
+ }
}
/*!
@@ -170,7 +177,7 @@ QAbstractFileEngineHandler::~QAbstractFileEngineHandler()
*/
QAbstractFileEngine *QAbstractFileEngine::create(const QString &fileName)
{
- {
+ if (qt_file_engine_handlers_in_use) {
QReadLocker locker(fileEngineHandlerMutex());
// check for registered handlers that can load the file