summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-03-31 12:52:30 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-04-16 08:04:32 (GMT)
commitd6d0b4f2b614453ce2ac96067408e0f3b071de78 (patch)
treeaa0401b8a54b19a9e329b8fb789bbfc8af89ca43 /src/corelib/io
parent80154fbd0aab812c5a16d3675741dd4531e7008a (diff)
downloadQt-d6d0b4f2b614453ce2ac96067408e0f3b071de78.zip
Qt-d6d0b4f2b614453ce2ac96067408e0f3b071de78.tar.gz
Qt-d6d0b4f2b614453ce2ac96067408e0f3b071de78.tar.bz2
Fixes: Faster string-splitting in QResource::findNode()
RevBy: Samuel Details: Creating the intermediate stringlist and appending all the temporary strings to it costs quite a bit. Fix this by introducing a StringSpliter class that is malloc-free and uses QStringRef instead. Found during S60 Performance week
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qresource.cpp44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp
index 3bdb352..779a742 100644
--- a/src/corelib/io/qresource.cpp
+++ b/src/corelib/io/qresource.cpp
@@ -60,6 +60,37 @@
QT_BEGIN_NAMESPACE
+
+class QStringSplitter
+{
+public:
+ QStringSplitter(const QString &s)
+ : m_string(s), m_data(m_string.constData()), m_len(s.length()), m_pos(0)
+ {
+ m_splitChar = QLatin1Char('/');
+ }
+
+ inline bool hasNext() {
+ while (m_pos < m_len && m_data[m_pos] == m_splitChar)
+ ++m_pos;
+ return m_pos < m_len;
+ }
+
+ inline QStringRef next() {
+ int start = m_pos;
+ while (m_pos < m_len && m_data[m_pos] != m_splitChar)
+ ++m_pos;
+ return QStringRef(&m_string, start, m_pos - start);
+ }
+
+ QString m_string;
+ const QChar *m_data;
+ QChar m_splitChar;
+ int m_len;
+ int m_pos;
+};
+
+
//resource glue
class QResourceRoot
{
@@ -618,12 +649,11 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const
//now iterate up the tree
int node = -1;
- QStringList segments = path.split(QLatin1Char('/'), QString::SkipEmptyParts);
-#ifdef DEBUG_RESOURCE_MATCH
- qDebug() << "****" << segments;
-#endif
- for(int i = 0; child_count && i < segments.size(); ++i) {
- const QString &segment = segments[i];
+
+ QStringSplitter splitter(path);
+ while (child_count && splitter.hasNext()) {
+ QStringRef segment = splitter.next();
+
#ifdef DEBUG_RESOURCE_MATCH
qDebug() << " CHILDREN" << segment;
for(int j = 0; j < child_count; ++j) {
@@ -665,7 +695,7 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const
(tree[offset+1] << 0);
offset += 2;
- if(i == segments.size()-1) {
+ if(!splitter.hasNext()) {
if(!(flags & Directory)) {
const short country = (tree[offset+0] << 8) +
(tree[offset+1] << 0);