D12145: autotests: Do not use QScopedPointer for plugins

Stefan BrĂ¼ns noreply at phabricator.kde.org
Thu Apr 12 17:11:22 UTC 2018


bruns added a comment.


  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.

REPOSITORY
  R286 KFileMetaData

BRANCH
  plugin-simple (branched from master)

REVISION DETAIL
  https://phabricator.kde.org/D12145

To: michaelh, #baloo, #frameworks, mgallien, bruns
Cc: alexeymin, ashaposhnikov, michaelh, astippich, spoorun, ngraham, bruns
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20180412/91e9878a/attachment.html>


More information about the Kde-frameworks-devel mailing list