make && make test
Details
- Reviewers
mgallien bruns - Group Reviewers
Baloo Frameworks - Commits
- R286:8b8857cb6bc3: autotests: Do not use QScopedPointer for plugins
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.
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.
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.