diff options
Diffstat (limited to 'src/corelib/io/qdir.cpp')
-rw-r--r-- | src/corelib/io/qdir.cpp | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index b31cf69..c0c62e1 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -802,14 +802,23 @@ QString QDir::convertSeparators(const QString &pathName) */ QString QDir::toNativeSeparators(const QString &pathName) { - QString n(pathName); #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN) - for (int i = 0; i < (int)n.length(); ++i) { - if (n[i] == QLatin1Char('/')) - n[i] = QLatin1Char('\\'); + int i = pathName.indexOf(QLatin1Char('/')); + if (i != -1) { + QString n(pathName); + + QChar * const data = n.data(); + data[i++] = QLatin1Char('\\'); + + for (; i < n.length(); ++i) { + if (data[i] == QLatin1Char('/')) + data[i] = QLatin1Char('\\'); + } + + return n; } #endif - return n; + return pathName; } /*! @@ -826,14 +835,23 @@ QString QDir::toNativeSeparators(const QString &pathName) */ QString QDir::fromNativeSeparators(const QString &pathName) { - QString n(pathName); #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN) - for (int i = 0; i < (int)n.length(); ++i) { - if (n[i] == QLatin1Char('\\')) - n[i] = QLatin1Char('/'); + int i = pathName.indexOf(QLatin1Char('\\')); + if (i != -1) { + QString n(pathName); + + QChar * const data = n.data(); + data[i++] = QLatin1Char('/'); + + for (; i < n.length(); ++i) { + if (data[i] == QLatin1Char('\\')) + data[i] = QLatin1Char('/'); + } + + return n; } #endif - return n; + return pathName; } /*! @@ -1615,9 +1633,13 @@ bool QDir::operator==(const QDir &dir) const if (d->filters == other->filters && d->sort == other->sort && d->nameFilters == other->nameFilters) { - d->resolveAbsoluteEntry(); - other->resolveAbsoluteEntry(); - return d->absoluteDirEntry.filePath().compare(other->absoluteDirEntry.filePath(), sensitive) == 0; + + // Assume directories are the same if path is the same + if (d->dirEntry.filePath() == other->dirEntry.filePath()) + return true; + + // Fallback to expensive canonical path computation + return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0; } return false; } |