autotests: Do not use QScopedPointer for plugins
ClosedPublic

Authored by michaelh on Apr 12 2018, 12:12 PM.

Details

Diff Detail

Repository
R286 KFileMetaData
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
michaelh created this revision.Apr 12 2018, 12:12 PM
Restricted Application added projects: Frameworks, Baloo. · View Herald TranscriptApr 12 2018, 12:12 PM
mgallien accepted this revision.Apr 12 2018, 3:50 PM

Thanks for having done it everywhere. I had missed that "detail".

This revision is now accepted and ready to land.Apr 12 2018, 3:50 PM

Just curious, why is this needed? To avoid dynamic memory allocations?

Just curious, why is this needed? To avoid dynamic memory allocations?

I asked on new code to avoid using an extractor allocated on heap instead of on stack. @michaelh just did the modifications in all tests to keep them coherent.

To me, the allocation on heap looks absolutely overhead.

Just curious, why is this needed? To avoid dynamic memory allocations?

see D12028. As I had copied that line, my conclusion was all or none. @mgallien: I'm also curious.

bruns added a comment.Apr 12 2018, 5:11 PM

The first question is - why should we use pointers at all (raw, std::unique_ptr, QScopedPointer, ...) for objects with local only scope.

The typical answer is Inheritance, see e.g. http://doc.qt.io/qt-5/qscopedpointer.html#details
A Base pointer can be used to hold an instance of Base, DerivedA or DerivedB.

If the exact type is known and the object has local scope, I don't know any reason to allocate the object on the heap. Allocating on the heap is just pointless overhead.

Even when the scope is not local, but the type is known, it is often useful to allocate the object on the stack and extend its scope using the constructor. This applies to any d-pointer classes, where the copy constructur is hardly more expensive than a move constructor (all of Qts implicitly shared classes), or where we have a move constructor in the first place.

This revision was automatically updated to reflect the committed changes.