summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-08-23 14:10:34 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-08-24 08:39:42 +0200
commit48c2f0b4b157e133605c99549893521775ede4da (patch)
treedc12fce9b32fe69f05b6202f14f07cb375b50312 /comphelper
parenta19d84ca25827d1fbe0ab9b276eeff843546ec87 (diff)
cache access in ConfigurationWrapper (tdf#105575)
If we repeatedly hit a config item like this: officecfg::Office::Common::Drawinglayer::MaximumPaperWidth::get() the stuff in configmgr because quite a bottleneck. So cache the access objects in ConfigurationWrapper. This change only affects the auto-generated code we use for the C++ officecfg:: configuration API Change-Id: Ie2adefc2319dfb362f1ef814690120e13abae6fd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120866 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/source/misc/configuration.cxx35
1 files changed, 32 insertions, 3 deletions
diff --git a/comphelper/source/misc/configuration.cxx b/comphelper/source/misc/configuration.cxx
index a03855b41c4b..3e8bb31ebb8a 100644
--- a/comphelper/source/misc/configuration.cxx
+++ b/comphelper/source/misc/configuration.cxx
@@ -10,9 +10,12 @@
#include <sal/config.h>
#include <cassert>
+#include <map>
#include <memory>
+#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>
@@ -128,10 +131,36 @@ bool comphelper::detail::ConfigurationWrapper::isReadOnly(OUString const & path)
!= 0;
}
-css::uno::Any comphelper::detail::ConfigurationWrapper::getPropertyValue(
- OUString const & path) const
+css::uno::Any comphelper::detail::ConfigurationWrapper::getPropertyValue(css::uno::Reference< css::uno::XComponentContext > const & context,
+ OUString const & path)
{
- return access_->getByHierarchicalName(path);
+ // 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
+ // else would be unwise because the cache could end up containing stale entries.
+ static std::mutex gMutex;
+ static std::map<OUString, css::uno::Reference< css::container::XNameAccess >> gAccessMap;
+
+ sal_Int32 idx = path.lastIndexOf("/");
+ assert(idx!=-1);
+ OUString parentPath = path.copy(0, idx);
+ OUString childName = path.copy(idx+1);
+
+ std::scoped_lock aGuard(gMutex);
+
+ // 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);
}
void comphelper::detail::ConfigurationWrapper::setPropertyValue(