comphelper/source/misc/configuration.cxx | 24 +++++++++--------------- include/comphelper/configuration.hxx | 5 ++--- 2 files changed, 11 insertions(+), 18 deletions(-)
New commits: commit 97b7511acfd9593051a611c71d307916097256dd Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Tue Aug 24 09:49:56 2021 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Tue Aug 24 13:41:17 2021 +0200 Simplify caching in ConfigurationWrapper A follow-up to 48c2f0b4b157e133605c99549893521775ede4da This allows to not call createInstanceWithArguments repeatedly. Change-Id: I1893b9b1b0f952ae7c650bab4fb0dfe2f331a129 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120883 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins diff --git a/comphelper/source/misc/configuration.cxx b/comphelper/source/misc/configuration.cxx index 3e8bb31ebb8a..67009cd9f864 100644 --- a/comphelper/source/misc/configuration.cxx +++ b/comphelper/source/misc/configuration.cxx @@ -15,7 +15,6 @@ #include <mutex> #include <string_view> -#include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/configuration/ReadOnlyAccess.hpp> #include <com/sun/star/configuration/ReadWriteAccess.hpp> @@ -131,8 +130,7 @@ bool comphelper::detail::ConfigurationWrapper::isReadOnly(OUString const & path) != 0; } -css::uno::Any comphelper::detail::ConfigurationWrapper::getPropertyValue(css::uno::Reference< css::uno::XComponentContext > const & context, - OUString const & path) +css::uno::Any comphelper::detail::ConfigurationWrapper::getPropertyValue(OUString const& path) const { // Cache the configuration access, since some of the keys are used in hot code. // Note that this cache is only used by the officecfg:: auto-generated code, using it for anything @@ -149,18 +147,14 @@ css::uno::Any comphelper::detail::ConfigurationWrapper::getPropertyValue(css::un // check cache auto it = gAccessMap.find(parentPath); - if (it != gAccessMap.end()) - return it->second->getByName(childName); - - // not in the cache, look it up - css::uno::Reference< css::lang::XMultiServiceFactory > provider = css::configuration::theDefaultProvider::get( - context ); - css::uno::Any arg(css::beans::NamedValue("nodepath", css::uno::Any(parentPath))); - css::uno::Reference< css::container::XNameAccess > access(provider->createInstanceWithArguments( - "com.sun.star.configuration.ConfigurationAccess", - { arg }), css::uno::UNO_QUERY_THROW); - gAccessMap.emplace(parentPath, access); - return access->getByName(childName); + if (it == gAccessMap.end()) + { + // not in the cache, look it up + css::uno::Reference<css::container::XNameAccess> access( + access_->getByHierarchicalName(parentPath), css::uno::UNO_QUERY_THROW); + it = gAccessMap.emplace(parentPath, access).first; + } + return it->second->getByName(childName); } void comphelper::detail::ConfigurationWrapper::setPropertyValue( diff --git a/include/comphelper/configuration.hxx b/include/comphelper/configuration.hxx index 27344e7a3672..1ed37dcd45c3 100644 --- a/include/comphelper/configuration.hxx +++ b/include/comphelper/configuration.hxx @@ -97,8 +97,7 @@ public: bool isReadOnly(OUString const & path) const; - static css::uno::Any getPropertyValue(css::uno::Reference< css::uno::XComponentContext > const & context, - OUString const & path); + css::uno::Any getPropertyValue(OUString const & path) const; static void setPropertyValue( std::shared_ptr< ConfigurationChanges > const & batch, @@ -211,7 +210,7 @@ template< typename T, typename U > struct ConfigurationProperty // Folding this into one statement causes a bogus error at least with // Red Hat GCC 4.6.2-1: css::uno::Any a( - detail::ConfigurationWrapper::getPropertyValue(context, + detail::ConfigurationWrapper::get(context).getPropertyValue( T::path())); return detail::Convert< U >::fromAny(a); }