QFileSystemEngineUnix: Don't stat before retrieving working path.
This is entirely unnecessary. If the path is bad, then getcwd and friends will fail. Doing an extra stat imposes an extra performance overhead without reason. Trivia: A dive into Qt's history shows that the stat dates back to: Sat Aug 12 14:24:36 1995 +0100 The original purpose of the stat was to avoid calling getcwd unless the path had actually changed. Subsequently, the caching was removed, but the stat remained. Change-Id: Ia4598dc74ded36516b3e10e7ab0eb5a6a5690466 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
015002fec9
commit
99e69dce78
@ -723,36 +723,29 @@ bool QFileSystemEngine::setCurrentPath(const QFileSystemEntry &path)
|
||||
QFileSystemEntry QFileSystemEngine::currentPath()
|
||||
{
|
||||
QFileSystemEntry result;
|
||||
QT_STATBUF st;
|
||||
if (QT_STAT(".", &st) == 0) {
|
||||
#if defined(__GLIBC__) && !defined(PATH_MAX)
|
||||
char *currentName = ::get_current_dir_name();
|
||||
if (currentName) {
|
||||
result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath());
|
||||
::free(currentName);
|
||||
}
|
||||
#else
|
||||
char currentName[PATH_MAX+1];
|
||||
if (::getcwd(currentName, PATH_MAX)) {
|
||||
#if defined(Q_OS_VXWORKS) && defined(VXWORKS_VXSIM)
|
||||
QByteArray dir(currentName);
|
||||
if (dir.indexOf(':') < dir.indexOf('/'))
|
||||
dir.remove(0, dir.indexOf(':')+1);
|
||||
|
||||
qstrncpy(currentName, dir.constData(), PATH_MAX);
|
||||
#endif
|
||||
result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath());
|
||||
}
|
||||
# if defined(QT_DEBUG)
|
||||
if (result.isEmpty())
|
||||
qWarning("QFileSystemEngine::currentPath: getcwd() failed");
|
||||
# endif
|
||||
#endif
|
||||
} else {
|
||||
# if defined(QT_DEBUG)
|
||||
qWarning("QFileSystemEngine::currentPath: stat(\".\") failed");
|
||||
# endif
|
||||
char *currentName = ::get_current_dir_name();
|
||||
if (currentName) {
|
||||
result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath());
|
||||
::free(currentName);
|
||||
}
|
||||
#else
|
||||
char currentName[PATH_MAX+1];
|
||||
if (::getcwd(currentName, PATH_MAX)) {
|
||||
#if defined(Q_OS_VXWORKS) && defined(VXWORKS_VXSIM)
|
||||
QByteArray dir(currentName);
|
||||
if (dir.indexOf(':') < dir.indexOf('/'))
|
||||
dir.remove(0, dir.indexOf(':')+1);
|
||||
|
||||
qstrncpy(currentName, dir.constData(), PATH_MAX);
|
||||
#endif
|
||||
result = QFileSystemEntry(QByteArray(currentName), QFileSystemEntry::FromNativePath());
|
||||
}
|
||||
# if defined(QT_DEBUG)
|
||||
if (result.isEmpty())
|
||||
qWarning("QFileSystemEngine::currentPath: getcwd() failed");
|
||||
# endif
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
x
Reference in New Issue
Block a user