From 8fb040b6c03ef2725419bfa7c9d58d21f2270b85 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Fri, 27 Jul 2012 11:53:46 +0200 Subject: Lazy initialize library paths For a lot of command line tools, library loading is not required, so don't waste a lot of time computing them. According to callgrind, this makes the QCoreApplication constructor factor 6 faster, and also removes a lot of stat() calls and other file system access. Change-Id: I0211f5303712fa0dcfc4168cce7025283c63c9d1 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcoreapplication.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 58d8957812..4c1f159552 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -403,8 +403,9 @@ void QCoreApplicationPrivate::appendApplicationPathToLibraryPaths() { #ifndef QT_NO_LIBRARY QStringList *app_libpaths = coreappdata()->app_libpaths; - Q_ASSERT(app_libpaths); - QString app_location( QCoreApplication::applicationFilePath() ); + if (!app_libpaths) + coreappdata()->app_libpaths = app_libpaths = new QStringList; + QString app_location = QCoreApplication::applicationFilePath(); app_location.truncate(app_location.lastIndexOf(QLatin1Char('/'))); app_location = QDir(app_location).canonicalPath(); if (QFile::exists(app_location) && !app_libpaths->contains(app_location)) @@ -589,12 +590,8 @@ void QCoreApplication::init() d->threadData->eventDispatcher = QCoreApplicationPrivate::eventDispatcher; #ifndef QT_NO_LIBRARY - if (!coreappdata()->app_libpaths) { - // make sure that library paths is initialized - libraryPaths(); - } else { + if (coreappdata()->app_libpaths) d->appendApplicationPathToLibraryPaths(); - } #endif #ifdef QT_EVAL -- cgit v1.2.3