From 5edaca5c892dbe07c0edb1ea0de4a115300e8ef0 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 2 May 2024 10:44:45 +0200 Subject: [PATCH] use boost::small_vector in cppuhelper shaves 5% off startup time Change-Id: I901e1112727eb7a50f70d1853386e0696fee7e5e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167000 Reviewed-by: Noel Grandin Tested-by: Jenkins --- cppuhelper/Library_cppuhelper.mk | 4 ++++ cppuhelper/source/servicemanager.cxx | 15 ++++----------- cppuhelper/source/servicemanager.hxx | 3 ++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cppuhelper/Library_cppuhelper.mk b/cppuhelper/Library_cppuhelper.mk index 3a1b4b776f66..5e8fe1616435 100644 --- a/cppuhelper/Library_cppuhelper.mk +++ b/cppuhelper/Library_cppuhelper.mk @@ -39,6 +39,10 @@ $(eval $(call gb_Library_use_static_libraries,cppuhelper,\ findsofficepath \ )) +$(eval $(call gb_Library_use_externals,cppuhelper,\ + boost_headers \ +)) + ifeq ($(OS),iOS) $(eval $(call gb_Library_add_cxxflags,cppuhelper,\ $(gb_OBJCXXFLAGS) \ diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx index 415d0edb0e3c..32b4976cf1e1 100644 --- a/cppuhelper/source/servicemanager.cxx +++ b/cppuhelper/source/servicemanager.cxx @@ -68,10 +68,7 @@ void insertImplementationMap( assert(destination != nullptr); for (const auto& [rName, rImpls] : source) { - std::vector< - std::shared_ptr< - cppuhelper::ServiceManager::Data::Implementation > > & impls - = (*destination)[rName]; + auto & impls = (*destination)[rName]; impls.insert(impls.end(), rImpls.begin(), rImpls.end()); } } @@ -87,13 +84,9 @@ void removeFromImplementationMap( assert(map != nullptr); for (const auto& rElement : elements) { - cppuhelper::ServiceManager::Data::ImplementationMap::iterator j( - map->find(rElement)); + auto j(map->find(rElement)); assert(j != map->end()); - std::vector< - std::shared_ptr< - cppuhelper::ServiceManager::Data::Implementation > >::iterator - k(std::find(j->second.begin(), j->second.end(), implementation)); + auto k(std::find(j->second.begin(), j->second.end(), implementation)); assert(k != j->second.end()); j->second.erase(k); if (j->second.empty()) { @@ -1139,7 +1132,7 @@ css::uno::Reference< css::container::XEnumeration > cppuhelper::ServiceManager::createContentEnumeration( OUString const & aServiceName) { - std::vector< std::shared_ptr< Data::Implementation > > impls; + boost::container::small_vector< std::shared_ptr< Data::Implementation >, 2 > impls; { std::unique_lock g(m_aMutex); Data::ImplementationMap::const_iterator i( diff --git a/cppuhelper/source/servicemanager.hxx b/cppuhelper/source/servicemanager.hxx index af80be25a183..8ab144b115ee 100644 --- a/cppuhelper/source/servicemanager.hxx +++ b/cppuhelper/source/servicemanager.hxx @@ -32,6 +32,7 @@ #include #include #include +#include namespace com::sun::star::lang { class XSingleComponentFactory; @@ -174,7 +175,7 @@ public: typedef std::unordered_map< OUString, - std::vector< std::shared_ptr< Implementation > > > + boost::container::small_vector< std::shared_ptr< Implementation >, 2 > > ImplementationMap; NamedImplementations namedImplementations;