Re: KFileItem optimization
Jakub Stachowski <[email protected]> Sun, 4 Jan 2009 13:30:28 +0100
| Newsgroups | gmane.comp.kde.devel.optimize |
|---|---|
| Message-ID | <[email protected]> |
--Boundary-00=_kvKYJ0b8dJ9Zqc4
Content-Type: multipart/alternative;
boundary="Boundary-00=_kvKYJpqVU6/++bD"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
--Boundary-00=_kvKYJpqVU6/++bD
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Dnia Saturday 03 January 2009, Jakub Stachowski napisa=C5=82:
> Hello,
[ ... ]
> Another possible optimization: for each item, KFileItemDelegate checks
> actual size of file icon. Is this really necessary? Or maybe it would be
> enough to check size for first icon in the view and then reuse it.
Some more checking shows that for given decoration size (stored in=20
option.decorationSize), actual icon size is always the same - one of the=20
common sizes like 64x64, 256x256 etc.
Caching the size makes laying out items about 20% faster (on top of previou=
s=20
patch).
KFileItemDelegate objects are not created in great numbers (one per view), =
so=20
adding two QSize fields will not have any effect on memory usage.
--Boundary-00=_kvKYJpqVU6/++bD
Content-Type: text/html;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-=
html40/strict.dtd"><html><head><meta name=3D"qrichtext" content=3D"1" /><st=
yle type=3D"text/css">p, li { white-space: pre-wrap; }</style></head><body =
style=3D" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-s=
tyle:normal;">Dnia Saturday 03 January 2009, Jakub Stachowski napisa=C5=82:=
<br>
> Hello,<br>
[ ... ]<br>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; ma=
rgin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-u=
ser-state:0;"><br></p>> Another possible optimization: for each item, K=
=46ileItemDelegate checks<br>
> actual size of file icon. Is this really necessary? Or maybe it would =
be<br>
> enough to check size for first icon in the view and then reuse it.<br>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; ma=
rgin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-u=
ser-state:0;"><br></p>Some more checking shows that for given decoration si=
ze (stored in option.decorationSize), actual icon size is always the same -=
one of the common sizes like 64x64, 256x256 etc.<br>
Caching the size makes laying out items about 20% faster (on top of previou=
s patch).<br>
KFileItemDelegate objects are not created in great numbers (one per view), =
so adding two QSize fields will not have any effect on memory usage.<br>
<p style=3D"-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; ma=
rgin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-u=
ser-state:0;"><br></p></body></html>
--Boundary-00=_kvKYJpqVU6/++bD--
--Boundary-00=_kvKYJ0b8dJ9Zqc4
Content-Type: text/x-patch;
charset="UTF-8";
name="iconopt.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="iconopt.patch"
Index: kfileitemdelegate.cpp
===================================================================
--- kfileitemdelegate.cpp (wersja 902836)
+++ kfileitemdelegate.cpp (kopia robocza)
@@ -124,6 +124,8 @@
Margin verticalMargin[NMargins];
Margin horizontalMargin[NMargins];
Margin *activeMargins;
+ mutable QSize cachedDecorationSize;
+ mutable QSize cachedIconSize;
};
@@ -459,7 +461,13 @@
{
Q_UNUSED(index)
- QSize iconSize = option.icon.actualSize(option.decorationSize);
+ if (option.decorationSize!=cachedDecorationSize || !cachedIconSize.isValid())
+ {
+ cachedDecorationSize = option.decorationSize;
+ cachedIconSize = option.icon.actualSize(option.decorationSize);
+ }
+
+ QSize iconSize=cachedIconSize;
if (!verticalLayout(option))
iconSize.rwidth() = option.decorationSize.width();
else if (iconSize.width() < option.decorationSize.width())
--Boundary-00=_kvKYJ0b8dJ9Zqc4
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=_kvKYJ0b8dJ9Zqc4--