summaryrefslogtreecommitdiff
path: root/include/unotools/weakref.hxx
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-11-03 16:07:11 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-11-04 08:18:57 +0100
commit4e0856fa11674e386c9b84dd40a702c83450166f (patch)
treeebce19c6961f10bf6ea8089e286e18c05e827a7e /include/unotools/weakref.hxx
parent6d2ee5d46ee0146a4990dfe3b3246371fece0826 (diff)
tdf#54857 use more static_cast in WeakReference::get
which shaves 3% off the load time here. Change-Id: I514dedc765ad12da2ad08e115c1ebf86c653c433 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142237 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/unotools/weakref.hxx')
-rw-r--r--include/unotools/weakref.hxx8
1 files changed, 7 insertions, 1 deletions
diff --git a/include/unotools/weakref.hxx b/include/unotools/weakref.hxx
index 023695dc14ae..9cf326d99625 100644
--- a/include/unotools/weakref.hxx
+++ b/include/unotools/weakref.hxx
@@ -29,6 +29,7 @@
#include <cppuhelper/weakref.hxx>
#include <cppuhelper/weak.hxx>
#include <rtl/ref.hxx>
+#include <type_traits>
namespace unotools
{
@@ -114,7 +115,12 @@ public:
rtl::Reference<interface_type> SAL_CALL get() const
{
css::uno::Reference<css::uno::XInterface> xInterface = WeakReferenceHelper::get();
- return dynamic_cast<interface_type*>(xInterface.get());
+ // If XInterface is an ambiguous base of interface_type, we have to use dynamic_cast,
+ // otherwise we can use the faster static_cast.
+ if constexpr (std::is_convertible_v<css::uno::XInterface, interface_type>)
+ return static_cast<interface_type*>(xInterface.get());
+ else
+ return dynamic_cast<interface_type*>(xInterface.get());
}
/** Gets a hard reference to the object.