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.grandin@collabora.co.uk>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user