Comparing KFileItems

Michael Pyne mpyne at kde.org
Fri Oct 19 01:11:23 BST 2012


On Thursday, October 18, 2012 13:54:09 Frank Reininghaus wrote:
> There are ways to fix or work around this problem inside Dolphin, but
> I'm wondering if it makes sense to change the way KFileItems are
> compared. If two items do not have the same d pointers, one could
> check if their URLs are equal and consider them equal in that case.
> Or, if that is not considered suffient for equality, do what
> KFileItem::cmp(const KFileItem&) does.
> 
> I see the following advantages and disadvantages:
> 
> Pro:
> 
> a) The implicit sharing is an implementation detail of KFileItem. At
> least I would not have expected that operator==() depends on this and
> only compares the d pointers.
> b) It could possibly prevent other bugs in the future and save debugging
> time.
> 
> Con:
> 
> Changing the way KFileItems are compared could considerably slow down
> comparisons of items which are not equal.
> 
> Any opinions about this?

Well, your pros are both correct (and you didn't even list that the current 
behavior is inconsistent between KFileItem::cmp() and KFileItem::operator==() 
;). But also, you list high CPU usage as a possible con, even though it's what 
got you into troubleshooting this in the first place!

I would recommend comparing the d-ptrs as done now as an early optimization 
and then falling back to KFileItem::cmp() (or the inlined equivalent) if the 
d-ptrs are different.

Regards,
 - Michael Pyne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20121018/d78d3fc8/attachment.sig>


More information about the kde-core-devel mailing list