chart2/source/inc/chartview/DrawModelWrapper.hxx | 2 chart2/source/view/main/ChartItemPool.cxx | 43 --------- chart2/source/view/main/ChartItemPool.hxx | 8 - chart2/source/view/main/DrawModelWrapper.cxx | 29 ++++++ comphelper/source/misc/configuration.cxx | 104 +++++------------------ include/comphelper/configuration.hxx | 2 6 files changed, 60 insertions(+), 128 deletions(-)
New commits: commit 05711aea7d52a69cc6932c6b5c032a1323c430d2 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Dec 1 15:19:12 2022 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Dec 28 09:17:05 2022 +0000 tdf#145599 Charts gets corrupted when you draw a line inside them This reverts commit 2ed8c34bca56c1a30d727b21d9096cb77e88197a use a single global item pool for chart2 draw model Change-Id: I640a981a2cbbed1cb9e6c0b0c239c78bb481e12e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143526 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> (cherry picked from commit c6aae3f4035f0a2dceba94b1956f5fc0ace3b3ee) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144803 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> (cherry picked from commit 64db5c602b25aeaefcbb8ac93413a8e6b6ef5ffa) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144806 Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org> Reviewed-by: Hossein <hoss...@libreoffice.org> Tested-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/chart2/source/inc/chartview/DrawModelWrapper.hxx b/chart2/source/inc/chartview/DrawModelWrapper.hxx index 0b4da35435d4..fb977528e8f1 100644 --- a/chart2/source/inc/chartview/DrawModelWrapper.hxx +++ b/chart2/source/inc/chartview/DrawModelWrapper.hxx @@ -40,7 +40,7 @@ class OOO_DLLPUBLIC_CHARTVIEW DrawModelWrapper final : private SdrModel private: rtl::Reference<SvxDrawPage> m_xMainDrawPage; rtl::Reference<SvxDrawPage> m_xHiddenDrawPage; - + rtl::Reference<SfxItemPool> m_xChartItemPool; VclPtr<OutputDevice> m_pRefDevice; public: diff --git a/chart2/source/view/main/ChartItemPool.cxx b/chart2/source/view/main/ChartItemPool.cxx index 37e78c116b76..3410bcdbf24e 100644 --- a/chart2/source/view/main/ChartItemPool.cxx +++ b/chart2/source/view/main/ChartItemPool.cxx @@ -216,48 +216,9 @@ MapUnit ChartItemPool::GetMetric(sal_uInt16 /* nWhich */) const return MapUnit::Map100thMM; } -static rtl::Reference<SfxItemPool> g_Pool1, g_Pool2, g_Pool3; - -/** If we let the libc runtime clean us up, we trigger a crash */ -namespace -{ -class TerminateListener : public ::cppu::WeakImplHelper< css::frame::XTerminateListener > -{ - void SAL_CALL queryTermination( const css::lang::EventObject& ) override - {} - void SAL_CALL notifyTermination( const css::lang::EventObject& ) override - { - g_Pool1.clear(); - g_Pool2.clear(); - g_Pool3.clear(); - } - virtual void SAL_CALL disposing( const ::css::lang::EventObject& ) override - {} -}; -}; - -SfxItemPool& ChartItemPool::GetGlobalChartItemPool() +rtl::Reference<SfxItemPool> ChartItemPool::CreateChartItemPool() { - if (!g_Pool1) - { - // similar logic to SdrModel's pool, but with our chart pool tagged on the end - g_Pool1 = new SdrItemPool(nullptr); - g_Pool2 = EditEngine::CreatePool(); - g_Pool3 = new ChartItemPool(); - g_Pool1->SetSecondaryPool(g_Pool2.get()); - - g_Pool1->SetDefaultMetric(MapUnit::Map100thMM); - g_Pool1->SetPoolDefaultItem(SfxBoolItem(EE_PARA_HYPHENATE, true) ); - g_Pool1->SetPoolDefaultItem(makeSvx3DPercentDiagonalItem (5)); - - g_Pool2->SetSecondaryPool(g_Pool3.get()); - g_Pool1->FreezeIdRanges(); - - css::uno::Reference< css::frame::XDesktop2 > xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext()); - css::uno::Reference< css::frame::XTerminateListener > xListener( new TerminateListener ); - xDesktop->addTerminateListener( xListener ); - } - return *g_Pool1; + return new ChartItemPool(); } } // namespace chart diff --git a/chart2/source/view/main/ChartItemPool.hxx b/chart2/source/view/main/ChartItemPool.hxx index 2ac440183740..74a7ab1ebb29 100644 --- a/chart2/source/view/main/ChartItemPool.hxx +++ b/chart2/source/view/main/ChartItemPool.hxx @@ -29,18 +29,16 @@ class ChartItemPool : public SfxItemPool private: std::unique_ptr<SfxItemInfo[]> pItemInfos; +public: ChartItemPool(); ChartItemPool(const ChartItemPool& rPool); - -protected: virtual ~ChartItemPool() override; -public: virtual rtl::Reference<SfxItemPool> Clone() const override; MapUnit GetMetric(sal_uInt16 nWhich) const override; - /// get the pure chart item pool - static SfxItemPool& GetGlobalChartItemPool(); + /// creates a pure chart item pool + static rtl::Reference<SfxItemPool> CreateChartItemPool(); }; } // namespace chart diff --git a/chart2/source/view/main/DrawModelWrapper.cxx b/chart2/source/view/main/DrawModelWrapper.cxx index aa7a002c967a..6a6488435f97 100644 --- a/chart2/source/view/main/DrawModelWrapper.cxx +++ b/chart2/source/view/main/DrawModelWrapper.cxx @@ -25,6 +25,7 @@ #include <svl/itempool.hxx> #include <svx/objfac3d.hxx> #include <svx/svdpage.hxx> +#include <svx/svx3ditems.hxx> #include <svx/xtable.hxx> #include <svx/svdoutl.hxx> #include <editeng/unolingu.hxx> @@ -43,12 +44,22 @@ namespace chart { DrawModelWrapper::DrawModelWrapper() -: SdrModel(&ChartItemPool::GetGlobalChartItemPool()) +: SdrModel() { + m_xChartItemPool = ChartItemPool::CreateChartItemPool(); + SetScaleUnit(MapUnit::Map100thMM); SetScaleFraction(Fraction(1, 1)); SetDefaultFontHeight(423); // 12pt + SfxItemPool* pMasterPool = &GetItemPool(); + pMasterPool->SetDefaultMetric(MapUnit::Map100thMM); + pMasterPool->SetPoolDefaultItem(SfxBoolItem(EE_PARA_HYPHENATE, true) ); + pMasterPool->SetPoolDefaultItem(makeSvx3DPercentDiagonalItem (5)); + + // append chart pool to end of pool chain + pMasterPool->GetLastPoolInChain()->SetSecondaryPool(m_xChartItemPool.get()); + pMasterPool->FreezeIdRanges(); SetTextDefaults(); //this factory needs to be created before first use of 3D scenes once upon an office runtime @@ -92,6 +103,22 @@ DrawModelWrapper::DrawModelWrapper() DrawModelWrapper::~DrawModelWrapper() { + //remove m_pChartItemPool from pool chain + if(m_xChartItemPool) + { + SfxItemPool* pPool = &GetItemPool(); + for (;;) + { + SfxItemPool* pSecondary = pPool->GetSecondaryPool(); + if(pSecondary == m_xChartItemPool.get()) + { + pPool->SetSecondaryPool (nullptr); + break; + } + pPool = pSecondary; + } + m_xChartItemPool.clear(); + } m_pRefDevice.disposeAndClear(); } commit 39d9822ec95cce01be118325572d9ffee044ffff Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Mon Dec 26 12:27:27 2022 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Dec 28 09:16:50 2022 +0000 Revert "optimize ConfigurationProperty::get()" (7.4 only) This reverts commit 7df433cdc33b4d6ba38eafad9282d015571433ef in libreoffice-7-4 only. See https://gerrit.libreoffice.org/c/core/+/144821 it seems it introduced https://crashreport.libreoffice.org/stats/signature/void%20rtl::str::release%3C_rtl_uString%3E(_rtl_uString*) which, at the moment, is the most reported crash in https://crashreport.libreoffice.org/stats/version/7.4.3.2 I sent Luboš an email about this more than a week ago but I didn't get any answer so let's revert it for the time being This commit also reverts b4b63d0c46979ad6b6aae5d6a4ea6672ea248e10 "try to fix some shutdown crashes" which was a blind fix. Unfortunately it didn't fix the issue since this commit is included in LibreOffice 7.4.3.2 Finally, adapt code to make loplugin:stringviewparam happy with getPropertyValue Change-Id: I870c4ab0c0d27ae4c9dd94c3abcc2c5eb17ab09d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144804 Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Tested-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> (cherry picked from commit df79a29ea20fb698d650be45a48c607f54476dea) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144805 Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org> Reviewed-by: Hossein <hoss...@libreoffice.org> diff --git a/comphelper/source/misc/configuration.cxx b/comphelper/source/misc/configuration.cxx index 1d6517fbb26d..59631dbccd83 100644 --- a/comphelper/source/misc/configuration.cxx +++ b/comphelper/source/misc/configuration.cxx @@ -10,11 +10,11 @@ #include <sal/config.h> #include <cassert> +#include <map> +#include <memory> #include <mutex> #include <string_view> -#include <unordered_map> -#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> @@ -27,12 +27,9 @@ #include <com/sun/star/lang/XLocalizable.hpp> #include <com/sun/star/uno/Any.hxx> #include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/util/XChangesListener.hpp> -#include <com/sun/star/util/XChangesNotifier.hpp> #include <comphelper/solarmutex.hxx> #include <comphelper/configuration.hxx> #include <comphelper/configurationlistener.hxx> -#include <cppuhelper/implbase.hxx> #include <rtl/ustring.hxx> #include <sal/log.hxx> #include <i18nlangtag/languagetag.hxx> @@ -109,70 +106,12 @@ comphelper::detail::ConfigurationWrapper::get() return WRAPPER; } -namespace -{ -std::mutex gMutex; -std::unordered_map<OUString, css::uno::Any> gPropertyCache; -css::uno::Reference< css::util::XChangesNotifier > gNotifier; -css::uno::Reference< css::util::XChangesListener > gListener; - -class ConfigurationChangesListener - : public ::cppu::WeakImplHelper<css::util::XChangesListener> -{ -public: - ConfigurationChangesListener() - {} - // util::XChangesListener - virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& ) override - { - std::scoped_lock aGuard(gMutex); - gPropertyCache.clear(); - } - virtual void SAL_CALL disposing(const css::lang::EventObject&) override - { - std::scoped_lock aGuard(gMutex); - gPropertyCache.clear(); - } -}; - -} // namespace - comphelper::detail::ConfigurationWrapper::ConfigurationWrapper(): context_(comphelper::getProcessComponentContext()), access_(css::configuration::ReadWriteAccess::create(context_, "*")) -{ - // Set up a configuration notifier to invalidate the cache as needed. - try - { - css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider( - css::configuration::theDefaultProvider::get( context_ ) ); - - // set root path - css::uno::Sequence< css::uno::Any > params { - css::uno::Any( css::beans::NamedValue{ "nodepath", css::uno::Any( OUString("/"))} ), - css::uno::Any( css::beans::NamedValue{ "locale", css::uno::Any( OUString("*"))} ) }; - - css::uno::Reference< css::uno::XInterface > xCfg - = xConfigProvider->createInstanceWithArguments(u"com.sun.star.configuration.ConfigurationAccess", - params); - - gNotifier = css::uno::Reference< css::util::XChangesNotifier >(xCfg, css::uno::UNO_QUERY); - assert(gNotifier.is()); - gListener = css::uno::Reference< ConfigurationChangesListener >(new ConfigurationChangesListener()); - gNotifier->addChangesListener(gListener); - } - catch(const css::uno::Exception&) - { - assert(false); - } -} +{} -comphelper::detail::ConfigurationWrapper::~ConfigurationWrapper() -{ - gPropertyCache.clear(); - gNotifier.clear(); - gListener.clear(); -} +comphelper::detail::ConfigurationWrapper::~ConfigurationWrapper() {} bool comphelper::detail::ConfigurationWrapper::isReadOnly(OUString const & path) const @@ -183,24 +122,31 @@ 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(std::u16string_view path) const { - std::scoped_lock aGuard(gMutex); // Cache the configuration access, since some of the keys are used in hot code. - auto it = gPropertyCache.find(path); - if( it != gPropertyCache.end()) - return it->second; + // 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("/"); + sal_Int32 idx = path.rfind('/'); assert(idx!=-1); - OUString parentPath = path.copy(0, idx); - OUString childName = path.copy(idx+1); - - css::uno::Reference<css::container::XNameAccess> access( - access_->getByHierarchicalName(parentPath), css::uno::UNO_QUERY_THROW); - css::uno::Any property = access->getByName(childName); - gPropertyCache.emplace(path, property); - return property; + OUString parentPath(path.substr(0, idx)); + OUString childName(path.substr(idx+1)); + + std::scoped_lock aGuard(gMutex); + + // check cache + auto it = gAccessMap.find(parentPath); + 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 3b8f8f1f7e93..222b9d5af124 100644 --- a/include/comphelper/configuration.hxx +++ b/include/comphelper/configuration.hxx @@ -87,7 +87,7 @@ public: bool isReadOnly(OUString const & path) const; - css::uno::Any getPropertyValue(OUString const & path) const; + css::uno::Any getPropertyValue(std::u16string_view path) const; static void setPropertyValue( std::shared_ptr< ConfigurationChanges > const & batch,