summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergio Martins <sergio.martins.qnx@kdab.com>2012-10-26 08:41:23 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-30 16:32:28 (GMT)
commit88be388557cb164eff3436973a57ba5914f4ad3b (patch)
tree6bdf55b27720e3ff131bf329ae9a745368cdf773
parentc16471dd7aa6ce9b9768e70de66763f73584d880 (diff)
downloadQt-88be388557cb164eff3436973a57ba5914f4ad3b.zip
Qt-88be388557cb164eff3436973a57ba5914f4ad3b.tar.gz
Qt-88be388557cb164eff3436973a57ba5914f4ad3b.tar.bz2
Blackberry: Fix QCoreApplication::applicationFilePath() performance.
Listing all files with QDir is slow. Instead, use argv[0] for zygotized apps and _cmdname() for non-zygotized. Apps run through the terminal will fall in the zygotized case, which is ok. Note about zygotized apps: Zygotized apps don't have an executable, they live in a shared object file. These apps are run through a deamon that forks and dlopens() the shared object ( for performance reasons ). For this reason we can't use _cmdname(), since it just contains the the file path of the daemon. On the other hand, non-zygotized apps have a bogus argv[0] when run through the navigator ( command line is fine ). Change-Id: I73d1cd742a70d1be36a8efe829671d6d7594a6fb Reviewed-by: Kevin Krammer <kevin.krammer@kdab.com> Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 3390438..bb07d74 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -76,6 +76,8 @@
#elif defined(Q_OS_UNIX)
# if defined(Q_OS_BLACKBERRY)
# include "qeventdispatcher_blackberry_p.h"
+# include <process.h>
+# include <unistd.h>
# else
# if !defined(QT_NO_GLIB)
# include "qeventdispatcher_glib_p.h"
@@ -2097,13 +2099,34 @@ QString QCoreApplication::applicationFilePath()
d->cachedApplicationFilePath = QFileInfo(qAppFileName()).filePath();
return d->cachedApplicationFilePath;
#elif defined(Q_OS_BLACKBERRY)
- QDir dir(QLatin1String("./app/native/"));
- QStringList executables = dir.entryList(QDir::Executable | QDir::Files);
- if (!executables.empty()) {
- //We assume that there is only one executable in the folder
- return dir.absoluteFilePath(executables.first());
+ if (!arguments().isEmpty()) { // args is never empty, but the navigator can change behaviour some day
+ QFileInfo fileInfo(arguments().at(0));
+ const bool zygotized = fileInfo.exists();
+ if (zygotized) {
+ // Handle the zygotized case:
+ d->cachedApplicationFilePath = QDir::cleanPath(fileInfo.absoluteFilePath());
+ return d->cachedApplicationFilePath;
+ }
+ }
+
+ // Handle the non-zygotized case:
+ const size_t maximum_path = static_cast<size_t>(pathconf("/",_PC_PATH_MAX));
+ char buff[maximum_path+1];
+ if (_cmdname(buff)) {
+ d->cachedApplicationFilePath = QDir::cleanPath(QString::fromLocal8Bit(buff));
+ return d->cachedApplicationFilePath;
} else {
- return QString();
+ qWarning("QCoreApplication::applicationFilePath: _cmdname() failed");
+ // _cmdname() won't fail, but just in case, fallback to the old method
+ QDir dir(QLatin1String("./app/native/"));
+ QStringList executables = dir.entryList(QDir::Executable | QDir::Files);
+ if (!executables.empty()) {
+ //We assume that there is only one executable in the folder
+ d->cachedApplicationFilePath = dir.absoluteFilePath(executables.first());
+ return d->cachedApplicationFilePath;
+ } else {
+ return QString();
+ }
}
#elif defined(Q_WS_MAC)
QString qAppFileName_str = qAppFileName();