diff options
author | Gunnar Sletta <gunnar@trolltech.com> | 2009-03-31 11:57:16 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar@trolltech.com> | 2009-04-16 08:02:07 (GMT) |
commit | 80154fbd0aab812c5a16d3675741dd4531e7008a (patch) | |
tree | 768a50ae716cc118558ea2df4b8543b5572e62f2 /src/corelib | |
parent | 0d433bcb83152c3a67fa81edcce36abf4b3191c4 (diff) | |
download | Qt-80154fbd0aab812c5a16d3675741dd4531e7008a.zip Qt-80154fbd0aab812c5a16d3675741dd4531e7008a.tar.gz Qt-80154fbd0aab812c5a16d3675741dd4531e7008a.tar.bz2 |
Fixes: Make QDir::cleanPath() slightly faster, by avoiding some detach calls..
RevBy: Samuel
Details: We have the size of the array and we don't realloc, so we can use direct
pointer access. This saves us a few detach() calls and some refcount
checking in the inner loops...
Found during S60 Performance week...
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qdir.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 6d75c59..d62328f 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -54,6 +54,8 @@ # include "qresource.h" #endif +#include "qvarlengtharray.h" + #include "../kernel/qcoreglobaldata_p.h" #include <stdlib.h> @@ -2065,11 +2067,13 @@ QString QDir::cleanPath(const QString &path) QString name = path; QChar dir_separator = separator(); if(dir_separator != QLatin1Char('/')) - name.replace(dir_separator, QLatin1Char('/')); + name.replace(dir_separator, QLatin1Char('/')); int used = 0, levels = 0; const int len = name.length(); - QVector<QChar> out(len); + QVarLengthArray<QChar> outVector(len); + QChar *out = outVector.data(); + const QChar *p = name.unicode(); for(int i = 0, last = -1, iwrite = 0; i < len; i++) { if(p[i] == QLatin1Char('/')) { @@ -2169,7 +2173,7 @@ QString QDir::cleanPath(const QString &path) if(used == len) ret = name; else - ret = QString(out.data(), used); + ret = QString(out, used); // Strip away last slash except for root directories if (ret.endsWith(QLatin1Char('/')) @@ -2232,7 +2236,7 @@ QStringList QDir::nameFiltersFromString(const QString &nameFilter) \snippet doc/src/snippets/code/src_corelib_io_qdir.cpp 13 - If the file name contains characters that cannot be part of a valid C++ function name + If the file name contains characters that cannot be part of a valid C++ function name (such as '-'), they have to be replaced by the underscore character ('_'). Note: This macro cannot be used in a namespace. It should be called from |