diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-05-31 15:41:34 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-06-02 17:41:44 +0200 |
commit | bcc30f482b0833460e38a48c07295a8e86b23478 (patch) | |
tree | f00e162d4cd8f9fddcf41ae9ba4971bb79a736b3 /editeng | |
parent | fc37066963a866eeb342b3a41b916f2574f5de28 (diff) |
tdf#144208 speedup doc with lots of redline(3)
Shave 5% off load time by using ItemInstanceManager subclasses for some
the more heavily used pool items
Change-Id: Id389ebb397e2fccfcbae28c8043fe05011b8f1cb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168307
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/items/textitem.cxx | 169 |
1 files changed, 167 insertions, 2 deletions
diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx index b4fa77d59d6f..914ca28a051d 100644 --- a/editeng/source/items/textitem.cxx +++ b/editeng/source/items/textitem.cxx @@ -445,9 +445,61 @@ void SvxFontItem::dumpAsXml(xmlTextWriterPtr pWriter) const // class SvxPostureItem -------------------------------------------------- +typedef std::unordered_map<size_t, const SfxPoolItem*> SvxPostureItemMap; + +namespace +{ + class SvxPostureItemInstanceManager : public ItemInstanceManager + { + SvxPostureItemMap maRegistered; + + public: + SvxPostureItemInstanceManager() + : ItemInstanceManager(typeid(SvxPostureItem).hash_code()) + { + } + + private: + static size_t hashCode(const SfxPoolItem&); + + // standard interface, accessed exclusively + // by implCreateItemEntry/implCleanupItemEntry + virtual const SfxPoolItem* find(const SfxPoolItem&) const override; + virtual void add(const SfxPoolItem&) override; + virtual void remove(const SfxPoolItem&) override; + }; + + size_t SvxPostureItemInstanceManager::hashCode(const SfxPoolItem& rItem) + { + auto const & rPostureItem = static_cast<const SvxPostureItem&>(rItem); + std::size_t seed(0); + o3tl::hash_combine(seed, rPostureItem.Which()); + o3tl::hash_combine(seed, rPostureItem. GetEnumValue()); + return seed; + } + + const SfxPoolItem* SvxPostureItemInstanceManager::find(const SfxPoolItem& rItem) const + { + auto aHit(maRegistered.find(hashCode(rItem))); + if (aHit != maRegistered.end()) + return aHit->second; + return nullptr; + } + + void SvxPostureItemInstanceManager::add(const SfxPoolItem& rItem) + { + maRegistered.insert({hashCode(rItem), &rItem}); + } + + void SvxPostureItemInstanceManager::remove(const SfxPoolItem& rItem) + { + maRegistered.erase(hashCode(rItem)); + } +} + ItemInstanceManager* SvxPostureItem::getItemInstanceManager() const { - static DefaultItemInstanceManager aInstanceManager(typeid(SvxPostureItem).hash_code()); + static SvxPostureItemInstanceManager aInstanceManager; return &aInstanceManager; } @@ -697,9 +749,63 @@ void SvxWeightItem::dumpAsXml(xmlTextWriterPtr pWriter) const // class SvxFontHeightItem ----------------------------------------------- +typedef std::unordered_map<size_t, const SfxPoolItem*> SvxFontHeightItemMap; + +namespace +{ + class SvxFontHeightItemInstanceManager : public ItemInstanceManager + { + SvxFontHeightItemMap maRegistered; + + public: + SvxFontHeightItemInstanceManager() + : ItemInstanceManager(typeid(SvxFontHeightItem).hash_code()) + { + } + + private: + static size_t hashCode(const SfxPoolItem&); + + // standard interface, accessed exclusively + // by implCreateItemEntry/implCleanupItemEntry + virtual const SfxPoolItem* find(const SfxPoolItem&) const override; + virtual void add(const SfxPoolItem&) override; + virtual void remove(const SfxPoolItem&) override; + }; + + size_t SvxFontHeightItemInstanceManager::hashCode(const SfxPoolItem& rItem) + { + auto const & rFontHeightItem = static_cast<const SvxFontHeightItem&>(rItem); + std::size_t seed(0); + o3tl::hash_combine(seed, rFontHeightItem.Which()); + o3tl::hash_combine(seed, rFontHeightItem.GetHeight()); + o3tl::hash_combine(seed, rFontHeightItem.GetProp()); + o3tl::hash_combine(seed, rFontHeightItem.GetPropUnit()); + return seed; + } + + const SfxPoolItem* SvxFontHeightItemInstanceManager::find(const SfxPoolItem& rItem) const + { + auto aHit(maRegistered.find(hashCode(rItem))); + if (aHit != maRegistered.end()) + return aHit->second; + return nullptr; + } + + void SvxFontHeightItemInstanceManager::add(const SfxPoolItem& rItem) + { + maRegistered.insert({hashCode(rItem), &rItem}); + } + + void SvxFontHeightItemInstanceManager::remove(const SfxPoolItem& rItem) + { + maRegistered.erase(hashCode(rItem)); + } +} + ItemInstanceManager* SvxFontHeightItem::getItemInstanceManager() const { - static DefaultItemInstanceManager aInstanceManager(typeid(SvxFontHeightItem).hash_code()); + static SvxFontHeightItemInstanceManager aInstanceManager; return &aInstanceManager; } @@ -2968,6 +3074,65 @@ void GetDefaultFonts( SvxFontItem& rLatin, SvxFontItem& rAsian, SvxFontItem& rCo } } +// class SvxRsidItem ----------------------------------------------------- + +typedef std::unordered_map<size_t, const SfxPoolItem*> SvxRsidItemMap; + +namespace +{ + class SvxRsidItemInstanceManager : public ItemInstanceManager + { + SvxRsidItemMap maRegistered; + + public: + SvxRsidItemInstanceManager() + : ItemInstanceManager(typeid(SvxRsidItem).hash_code()) + { + } + + private: + static size_t hashCode(const SfxPoolItem&); + + // standard interface, accessed exclusively + // by implCreateItemEntry/implCleanupItemEntry + virtual const SfxPoolItem* find(const SfxPoolItem&) const override; + virtual void add(const SfxPoolItem&) override; + virtual void remove(const SfxPoolItem&) override; + }; + + size_t SvxRsidItemInstanceManager::hashCode(const SfxPoolItem& rItem) + { + auto const & rRsidItem = static_cast<const SvxRsidItem&>(rItem); + std::size_t seed(0); + o3tl::hash_combine(seed, rRsidItem.Which()); + o3tl::hash_combine(seed, rRsidItem.GetValue()); + return seed; + } + + const SfxPoolItem* SvxRsidItemInstanceManager::find(const SfxPoolItem& rItem) const + { + auto aHit(maRegistered.find(hashCode(rItem))); + if (aHit != maRegistered.end()) + return aHit->second; + return nullptr; + } + + void SvxRsidItemInstanceManager::add(const SfxPoolItem& rItem) + { + maRegistered.insert({hashCode(rItem), &rItem}); + } + + void SvxRsidItemInstanceManager::remove(const SfxPoolItem& rItem) + { + maRegistered.erase(hashCode(rItem)); + } +} + +ItemInstanceManager* SvxRsidItem::getItemInstanceManager() const +{ + static SvxRsidItemInstanceManager aInstanceManager; + return &aInstanceManager; +} bool SvxRsidItem::QueryValue( uno::Any& rVal, sal_uInt8 ) const { |