Re: KFileItem optimization
David Faure <[email protected]> Mon, 5 Jan 2009 18:05:30 +0100
| Newsgroups | gmane.comp.kde.devel.optimize |
|---|---|
| Organization | KDE |
| Message-ID | <[email protected]> |
--Boundary-00=_a3jYJSjVv8uL9PM
Content-Type: text/plain;
charset="iso-8859-15"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
On Saturday 03 January 2009, Jakub Stachowski wrote:
> It is slow operation, because of mime-
> >is("application/x-desktop") check, which constructs KMimeType object for
> application/x-desktop type again and again.
Yep. I have on my todo list "optimizing KMimeType::is by adding a way in ksycoca
to get a mimetype's parent without having to load it completely".
> Attached patch adds fast path to
> KMimeType::is by allowing to ignore resolving aliases. It is not a problem in
> case of KFileItem, because application/x-desktop is not an alias.
Well, it is not at the moment, but who knows about the future?
Any mimetype could be turned into an alias later on in order to solve some bug,
like if we merge two mimetypes.
Also, this is solving the wrong problem IMHO. Resolving aliases _is_ fast,
since they are in a QMap in KMimeTypeFactory. The problem is just that findMimeTypeByName
does both: resolving aliases _and_ loading the mimetype, which is the slow part.
How about we resolve aliases without loading the mimetype? This would solve
this in a much nicer way - no need for new API, the code would remain generic
but just faster.
Can you check the performance with this new patch?
(This is orthogonal to my planned KMimeType::is() performance improvement
which would make it even faster, btw).
--
David Faure, [email protected], sponsored by Qt Software @ Nokia to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
--Boundary-00=_a3jYJSjVv8uL9PM
Content-Type: text/x-diff;
charset="iso 8859-15";
name="inherits_speedup.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="inherits_speedup.diff"
Index: kmimetype.cpp
===================================================================
--- kmimetype.cpp (revision 905785)
+++ kmimetype.cpp (working copy)
@@ -597,9 +597,9 @@
return QString();
}
-bool KMimeTypePrivate::inherits(KMimeType::Ptr mime) const
+bool KMimeTypePrivate::inherits(const QString& mime) const
{
- if (mime && m_strName == mime->d_func()->m_strName) {
+ if (m_strName == mime) {
return true;
}
foreach( const QString& parent, parentMimeTypes() ) {
@@ -617,7 +617,9 @@
Q_D(const KMimeType);
if (name() == mimeTypeName)
return true;
- KMimeType::Ptr mime = KMimeTypeFactory::self()->findMimeTypeByName(mimeTypeName, KMimeType::ResolveAliases);
+ QString mime = KMimeTypeFactory::self()->resolveAlias(mimeTypeName);
+ if (mime.isEmpty())
+ mime = mimeTypeName;
return d->inherits(mime);
}
Index: kmimetypefactory.h
===================================================================
--- kmimetypefactory.h (revision 905785)
+++ kmimetypefactory.h (working copy)
@@ -61,14 +61,15 @@
*/
virtual KMimeType::Ptr findMimeTypeByName(const QString &_name, KMimeType::FindByNameOption options = KMimeType::DontResolveAlias);
-private: // only for KMimeType
- friend class KMimeType;
- friend class KMimeFileParserTest;
/**
* Check if mime is an alias, and return the canonical name for it if it is.
*/
- QString resolveAlias(const QString& mime);
+ QString resolveAlias(const QString& mime) const;
+private: // only for KMimeType
+ friend class KMimeType;
+ friend class KMimeFileParserTest;
+
/**
* Find a mimetype from a filename (using the pattern list)
* @param filename filename to check.
Index: kmimetypefactory.cpp
===================================================================
--- kmimetypefactory.cpp (revision 905785)
+++ kmimetypefactory.cpp (working copy)
@@ -149,7 +149,7 @@
}
-QString KMimeTypeFactory::resolveAlias(const QString& mime)
+QString KMimeTypeFactory::resolveAlias(const QString& mime) const
{
return m_aliases.value(mime);
}
--Boundary-00=_a3jYJSjVv8uL9PM
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Kde-optimize mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kde-optimize
--Boundary-00=_a3jYJSjVv8uL9PM--