include/svl/poolitem.hxx | 3 ++- svl/source/items/poolitem.cxx | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-)
New commits: commit 32b295b7392c4a14def87e4fa0b9fa74f9441ffd Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Jun 25 14:22:25 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Wed Jun 26 08:44:54 2024 +0200 speed up DefaultItemInstanceManager we can store the registered items in a map indexed by which-id, and avoid most of the search cost Change-Id: Ib3fbed436bc034e603819cfef8223dcc77eb7f06 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169528 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx index 4f71bc871a58..bdfb814e3c0a 100644 --- a/include/svl/poolitem.hxx +++ b/include/svl/poolitem.hxx @@ -33,6 +33,7 @@ #include <tools/long.hxx> #include <boost/property_tree/ptree_fwd.hpp> #include <unordered_set> +#include <unordered_map> class IntlWrapper; @@ -638,7 +639,7 @@ private: // that specific Item (see other derivations) class SVL_DLLPUBLIC DefaultItemInstanceManager : public ItemInstanceManager { - std::unordered_set<const SfxPoolItem*> maRegistered; + std::unordered_map<sal_uInt16, std::unordered_set<const SfxPoolItem*>> maRegistered; public: DefaultItemInstanceManager(const std::size_t aClassHash) diff --git a/svl/source/items/poolitem.cxx b/svl/source/items/poolitem.cxx index 491c30a7f50a..a9db94057d8a 100644 --- a/svl/source/items/poolitem.cxx +++ b/svl/source/items/poolitem.cxx @@ -503,16 +503,25 @@ void listAllocatedSfxPoolItems() const SfxPoolItem* DefaultItemInstanceManager::find(const SfxPoolItem& rItem) const { - for (const auto& rCandidate : maRegistered) - if (rCandidate->Which() == rItem.Which() && *rCandidate == rItem) + auto it = maRegistered.find(rItem.Which()); + if (it == maRegistered.end()) + return nullptr; + for (const auto& rCandidate : it->second) + if (*rCandidate == rItem) return rCandidate; return nullptr; } -void DefaultItemInstanceManager::add(const SfxPoolItem& rItem) { maRegistered.insert(&rItem); } +void DefaultItemInstanceManager::add(const SfxPoolItem& rItem) +{ + maRegistered[rItem.Which()].insert(&rItem); +} -void DefaultItemInstanceManager::remove(const SfxPoolItem& rItem) { maRegistered.erase(&rItem); } +void DefaultItemInstanceManager::remove(const SfxPoolItem& rItem) +{ + maRegistered[rItem.Which()].erase(&rItem); +} ItemInstanceManager* SfxPoolItem::getItemInstanceManager() const { return nullptr; }