KDE/kdelibs/kded
David Faure
faure at kde.org
Mon Jul 19 19:46:54 CEST 2010
SVN commit 1151848 by dfaure:
Make mimetype parsing 29% faster by using QXmlStreamReader instead of QDomDocument
before: 1962378 instructions per createEntry, 570 ms total (for kbuildsycoca --noincremental)
after: 1378515 instructions per createEntry, 410 ms total (for kbuildsycoca --noincremental)
Impact on the overall kbuildsycoca --noincremental run: 8% speedup, and mimetype parsing
went down from 26% of the total cpu time to 20.2% of the now-shorter cpu time, moving it
below KConfig parsing and ksycoca saving.
CCMAIL: kde-optimize at kde.org
M +21 -17 kbuildmimetypefactory.cpp
--- trunk/KDE/kdelibs/kded/kbuildmimetypefactory.cpp #1151847:1151848
@@ -31,7 +31,7 @@
#include <kdesktopfile.h>
#include <QtCore/QHash>
#include <QtCore/QFile>
-#include <QtXml/QDomAttr>
+#include <QXmlStreamReader>
KBuildMimeTypeFactory::KBuildMimeTypeFactory() :
KMimeTypeFactory(), m_parser(this),
@@ -112,42 +112,46 @@
QFile qfile(fullPath);
if (!qfile.open(QFile::ReadOnly))
continue;
- QDomDocument doc;
- if (!doc.setContent(&qfile)) {
- kWarning() << "Parse error in " << fullPath;
+
+ QXmlStreamReader xml(&qfile);
+ if (xml.readNextStartElement()) {
+ if (xml.name() != "mime-type") {
continue;
}
- const QDomElement mimeTypeElement = doc.documentElement();
- if (mimeTypeElement.tagName() != "mime-type")
- continue;
- name = mimeTypeElement.attribute("type");
+ name = xml.attributes().value("type").toString();
if (name.isEmpty())
continue;
- for ( QDomElement e = mimeTypeElement.firstChildElement();
- !e.isNull();
- e = e.nextSiblingElement() ) {
- const QString tag = e.tagName();
+ while (xml.readNextStartElement()) {
+ const QStringRef tag = xml.name();
if (tag == "comment") {
- QString lang = e.attribute("xml:lang");
+ QString lang = xml.attributes().value("xml:lang").toString();
+ const QString text = xml.readElementText();
if (lang.isEmpty()) {
- comment = e.text();
+ comment = text;
lang = "en";
}
- commentsByLanguage.insert(lang, e.text());
+ commentsByLanguage.insert(lang, text);
+ continue; // we called readElementText, so we're at the EndElement already.
} else if (tag == "icon") { // as written out by shared-mime-info >= 0.40
- userIcon = e.attribute("name");
+ userIcon = xml.attributes().value("name").toString();
} else if (tag == "glob-deleteall") { // as written out by shared-mime-info > 0.60
mainPattern.clear();
m_parsedMimeTypes[name] = QString();
} else if (tag == "glob" && mainPattern.isEmpty()) { // as written out by shared-mime-info > 0.60
- const QString pattern = e.attribute("pattern");
+ const QString pattern = xml.attributes().value("pattern").toString();
if (pattern.startsWith('*')) {
mainPattern = pattern;
}
}
+ xml.skipCurrentElement();
}
+ if (xml.name() != "mime-type") {
+ kFatal() << "Programming error in KBuildMimeTypeFactory::createEntry, please create a bug report on http://bugs.kde.org and attach the file" << fullPath;
}
+ }
+ }
+
if (name.isEmpty()) {
return 0;
}
More information about the Kde-optimize
mailing list