diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-02-21 16:00:52 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-02-22 12:27:55 +0100 |
commit | 27352b81638f2f1e792ab48ec532eaacf6f61718 (patch) | |
tree | eb744c30643272b219d59f2782ffc96f62bf379c /include | |
parent | 6ccdd0d164b16da9a13ab5d8290a1a0f041caaf7 (diff) |
Add XWeak constructor and operator= to uno::WeakReference
which is faster since we can skip the UNO_QUERY.
Change-Id: Id95ad9f3568213e974bd13659d92d4ea94dbfbd6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130282
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include')
-rw-r--r-- | include/cppuhelper/weakref.hxx | 34 | ||||
-rw-r--r-- | include/unotools/weakref.hxx | 13 |
2 files changed, 45 insertions, 2 deletions
diff --git a/include/cppuhelper/weakref.hxx b/include/cppuhelper/weakref.hxx index 9b41df598340..a5858b2e8805 100644 --- a/include/cppuhelper/weakref.hxx +++ b/include/cppuhelper/weakref.hxx @@ -42,6 +42,7 @@ namespace uno { class OWeakRefListener; +class XWeak; /** The WeakReferenceHelper holds a weak reference to an object. @@ -79,6 +80,16 @@ public: */ WeakReferenceHelper( const css::uno::Reference< css::uno::XInterface > & xInt ); +#if defined LIBO_INTERNAL_ONLY + /** Initialize this reference with the hard interface reference xWeak. This + is faster than the XInterface constructor because we can skip doing an + UNO_QUERY. + + @param xWeak another hard interface reference + */ + WeakReferenceHelper( const css::uno::Reference< css::uno::XWeak > & xWeak ); +#endif + /** Releases this reference. */ ~WeakReferenceHelper(); @@ -102,6 +113,17 @@ public: WeakReferenceHelper & SAL_CALL operator = ( const css::uno::Reference< css::uno::XInterface > & xInt ); +#if defined LIBO_INTERNAL_ONLY + /** Releases this reference and takes over hard reference xWeak. This + is faster than the XInterface constructor because we can skip doing an + UNO_QUERY. + + @param xWeak another hard reference + */ + WeakReferenceHelper & operator = ( + const css::uno::Reference< css::uno::XWeak > & xWeak ); +#endif + /** Returns true if both weak refs reference to the same object. @param rObj another weak ref @@ -176,6 +198,18 @@ public: const css::uno::Reference< interface_type > & xInt ) { WeakReferenceHelper::operator=(xInt); return *this; } +#if defined LIBO_INTERNAL_ONLY + /** Releases this reference and takes over hard reference xWeak. This + is faster than the XInterface constructor because we can skip doing an + UNO_QUERY. + + @param xWeak another hard reference + */ + WeakReference & operator = ( + const css::uno::Reference< css::uno::XWeak > & xWeak ) + { WeakReferenceHelper::operator=(xWeak); return *this; } +#endif + /** Gets a hard reference to the object. @return hard reference or null, if the weakly referenced interface has gone diff --git a/include/unotools/weakref.hxx b/include/unotools/weakref.hxx index 189df22d5359..ca5682416033 100644 --- a/include/unotools/weakref.hxx +++ b/include/unotools/weakref.hxx @@ -77,14 +77,22 @@ public: { } - /** Copy ctor. Initialize this reference with a hard reference. + /** Copy ctor. Initialize this reference with a hard reference. @param rRef another hard ref */ +#if defined LIBO_INTERNAL_ONLY + WeakReference(interface_type* pRef) + : WeakReferenceHelper( + css::uno::Reference<css::uno::XWeak>(static_cast<cppu::OWeakObject*>(pRef))) + { + } +#else WeakReference(interface_type* pRef) : WeakReferenceHelper(static_cast<cppu::OWeakObject*>(pRef)) { } +#endif /** Releases this reference and takes over hard reference xInt. If the implementation behind xInt does not support XWeak @@ -106,7 +114,8 @@ public: WeakReference& operator=(interface_type* pInt) { - WeakReferenceHelper::operator=(static_cast<::cppu::OWeakObject*>(pInt)); + WeakReferenceHelper::operator=( + css::uno::Reference<css::uno::XWeak>(static_cast<::cppu::OWeakObject*>(pInt))); return *this; } |