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>
diff --git a/include/unotools/weakref.hxx b/include/unotools/weakref.hxx
index 023695d..9cf326d 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.