D10341: Allow move semantics to be generated for KFileItem. The existing copy constructor, destructor and copy assignment operator are now also generated by the compiler.
David Faure
noreply at phabricator.kde.org
Wed Feb 7 23:02:16 UTC 2018
dfaure added a comment.
I like the idea of enabling moves for KFileItem very much.
But here's a fun fact: your unittest passes even without the rest of the patch.
PASS : KFileItemTest::testMove()
That's because std::move() doesn't move, it only makes the argument eligible for e.g. a move ctor, but will call a copy ctor if there's no move ctor. So that test is not really testing that move works ;)
That's always a bit tricky to test, I guess, because one can't really rely on the state of the moved-from object to be anything in particular. And we want =default, not to implement some counters in there.
Oh well, then maybe there's no real way to unittest that moving works.
Anyhow, the thing I'm wondering is the following: does the rule-of-zero lead to more opportunities for optimizations by the compiler, who can see "from the outside" that the 5 special members are the default generated ones, while your patch "hides" the implementation, lowering the visibility for the compiler in the rest of the code? Well, one could just move the 5 "=default" to the header to fix that.
Of course in both cases (rule-of-zero or 5*=default in the header), it means we are tied to the 5 defaults for all of KF5, for BIC reasons. But that seems rather sensible in this case (the only member will always be the d pointer, and it's unlikely we'll move away from refcounting...).
And in fact the other reason against rule-of-zero is that we can't just remove the copy-ctor and operator=, that would be BIC (existing code links to it).
In summary: this looks good to me, I'm just wondering if inlining the 5 "=default" wouldn't be better, for optimization purposes.
REPOSITORY
R241 KIO
REVISION DETAIL
https://phabricator.kde.org/D10341
To: markg, dfaure, mwolff
Cc: ngraham, #frameworks, michaelh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20180207/587e8132/attachment.html>
More information about the Kde-frameworks-devel
mailing list