diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-09-19 11:13:53 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-09-20 17:48:08 +0200 |
commit | afd918a81bc2dce4830bc94cbd88b9038f5715ff (patch) | |
tree | 5d6d46d4c149be04b34066f15fff470d19ec9127 /include/svl/itemset.hxx | |
parent | 88b72d85ef82a5a6ca019ef9b88f5389db067c83 (diff) |
introduce SfxItemSetFixed and use it in DefaultProperties
DefaultProperties::SetObjectItemSet is very hot when loading
shapes, and a large chunk of that cost is allocating the pool item
array.
So use a template class to allocate the array in-line to the class,
which means it can be allocated on-stack.
Change-Id: Ic53b41f35784726362de38fceb35f8634cddf0a4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122310
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/svl/itemset.hxx')
-rw-r--r-- | include/svl/itemset.hxx | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx index 760fafd03992..f0ea42835073 100644 --- a/include/svl/itemset.hxx +++ b/include/svl/itemset.hxx @@ -16,8 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_SVL_ITEMSET_HXX -#define INCLUDED_SVL_ITEMSET_HXX +#pragma once #include <sal/config.h> @@ -39,10 +38,10 @@ class SAL_WARN_UNUSED SVL_DLLPUBLIC SfxItemSet SfxItemPool* m_pPool; ///< pool that stores the items const SfxItemSet* m_pParent; ///< derivation - std::unique_ptr<SfxPoolItem const*[]> - m_pItems; ///< array of items + SfxPoolItem const** m_ppItems; ///< pointer to array of items, we allocate and free this unless m_bItemsFixed==true WhichRangesContainer m_pWhichRanges; ///< array of Which Ranges sal_uInt16 m_nCount; ///< number of items + bool m_bItemsFixed; ///< true if this is a SfxItemSetFixed object friend class SfxItemPoolCache; friend class SfxAllItemSet; @@ -53,7 +52,7 @@ private: SfxItemSet( SfxItemPool & pool, const WhichRangesContainer& wids, std::size_t items ); public: - SfxPoolItem const** GetItems_Impl() const { return m_pItems.get(); } + SfxPoolItem const** GetItems_Impl() const { return m_ppItems; } private: const SfxItemSet& operator=(const SfxItemSet &) = delete; @@ -69,6 +68,8 @@ protected: /** special constructor for SfxAllItemSet */ enum class SfxAllItemSetFlag { Flag }; SfxItemSet( SfxItemPool&, SfxAllItemSetFlag ); + /** special constructor for SfxItemSetFixed */ + SfxItemSet( SfxItemPool&, WhichRangesContainer&& ranges, SfxPoolItem const ** ppItems ); public: SfxItemSet( const SfxItemSet& ); @@ -223,6 +224,17 @@ private: virtual const SfxPoolItem* PutImpl( const SfxPoolItem&, sal_uInt16 nWhich, bool bPassingOwnership ) override; }; -#endif // INCLUDED_SVL_ITEMSET_HXX + +// Allocate the items array inside the object, to reduce allocation cost. +// +template<sal_uInt16 nWID1, sal_uInt16 nWID2> +class SfxItemSetFixed : public SfxItemSet +{ +public: + SfxItemSetFixed( SfxItemPool& rPool) + : SfxItemSet(rPool, WhichRangesContainer(svl::Items_t<nWID1, nWID2>{}), m_aItems) {} +private: + const SfxPoolItem* m_aItems[nWID2 - nWID1 + 1] = {}; +}; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |