diff options
author | Armin Le Grand (allotropia) <armin.le.grand.extern@allotropia.de> | 2024-07-10 15:54:40 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@me.com> | 2024-07-11 11:01:01 +0200 |
commit | ece698a575710ac7de0c628ef7b8dc7f59e03108 (patch) | |
tree | 130c5624cac6b15467c320528e54f5f64fb09fa6 /svl/source/items | |
parent | 27829e4a6c5a4a1162599550c46b5e7f974aba91 (diff) |
ITEM: replaced typeid/hash_code with SfxItemType
for the ItemInstanceManager the identification was done
using typeid/hash_code, but that has problems - it is
only defined to be identical for two instances of the
same type, but other types can have the same code.
Thanks to Noel to find that out, that is not reliable
to be used.
In the meantime we have SfxItemType to identify Item
instances, so I changed the code to use that.
The master had five additionally added Items that
use the (2a) method of this mechanism (see comments
in svl/source/items/globalpool.cxx for that). The
gloal is to use as less as possible of this Items in
that mechanism, so I checked.
For four of these hashing was used, so the mem/runtime
aspect is okay -> access is fast enough to prefer
mem over runtime. Adding hashed Items (or any other
fast mechanism) is always okay.
One did not have that (SvxBoxItem) and used just the
fallback ItemInstanceManager, so I removed it. We
now have 18 Items for which that mechanism is
initialized immediately.
Noel also already moved the countdown for starting
to use the mechanism in case of default handling
(case (1), NUMBER_OF_UNSHARED_INSTANCES) to the
unorderd_set. someting I had already planned to do,
too - thanks!
Change-Id: Icf6f427e5ea64672f385357aaad75bb5b7fcbf98
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170314
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'svl/source/items')
-rw-r--r-- | svl/source/items/cenumitm.cxx | 7 | ||||
-rw-r--r-- | svl/source/items/globalpool.cxx | 26 |
2 files changed, 16 insertions, 17 deletions
diff --git a/svl/source/items/cenumitm.cxx b/svl/source/items/cenumitm.cxx index e5e53e18d0b7..dbf3b4baa75e 100644 --- a/svl/source/items/cenumitm.cxx +++ b/svl/source/items/cenumitm.cxx @@ -92,8 +92,9 @@ namespace SfxBoolItemMap maRegistered; public: - SfxBoolItemInstanceManager() - : ItemInstanceManager(typeid(SfxBoolItem).hash_code()) + SfxBoolItemInstanceManager(SfxItemType aSfxItemType) + : ItemInstanceManager(aSfxItemType) + , maRegistered() { } @@ -158,7 +159,7 @@ namespace ItemInstanceManager* SfxBoolItem::getItemInstanceManager() const { - static SfxBoolItemInstanceManager aInstanceManager; + static SfxBoolItemInstanceManager aInstanceManager(ItemType()); return &aInstanceManager; } diff --git a/svl/source/items/globalpool.cxx b/svl/source/items/globalpool.cxx index ba16d3874429..c5ecfba62c2a 100644 --- a/svl/source/items/globalpool.cxx +++ b/svl/source/items/globalpool.cxx @@ -125,7 +125,7 @@ void DefaultItemInstanceManager::remove(const SfxPoolItem& rItem) // ignored and start sharing ALL Item derivations instantly. class InstanceManagerHelper { - typedef std::unordered_map<std::size_t, std::pair<sal_uInt16, DefaultItemInstanceManager*>> + typedef std::unordered_map<SfxItemType, std::pair<sal_uInt16, DefaultItemInstanceManager*>> managerTypeMap; managerTypeMap maManagerPerType; @@ -153,15 +153,14 @@ public: // hopefully fastest) incarnations ItemInstanceManager* pManager(rItem.getItemInstanceManager()); - // Check for correct hash, there may be derivations of that class. + // Check for correct SfxItemType, there may be derivations of that class. // Note that Managers from the Items are *not* added to local list, - // they are expected to be static instances at the Items - const std::size_t aHash(typeid(rItem).hash_code()); - if (nullptr != pManager && pManager->getClassHash() == aHash) + // they are expected to be static instances at the Items for fastest access + if (nullptr != pManager && pManager->ItemType() == rItem.ItemType()) return pManager; // check local memory for existing entry - managerTypeMap::iterator aHit(maManagerPerType.find(aHash)); + managerTypeMap::iterator aHit(maManagerPerType.find(rItem.ItemType())); // no instance yet if (aHit == maManagerPerType.end()) @@ -170,14 +169,14 @@ public: if (g_bShareImmediately) { // create, insert locally and immediately start sharing - DefaultItemInstanceManager* pNew(new DefaultItemInstanceManager(aHash)); - maManagerPerType.insert({ aHash, std::make_pair(0, pNew) }); + DefaultItemInstanceManager* pNew(new DefaultItemInstanceManager(rItem.ItemType())); + maManagerPerType.insert({ rItem.ItemType(), std::make_pair(0, pNew) }); return pNew; } // start countdown from NUMBER_OF_UNSHARED_INSTANCES until zero is reached maManagerPerType.insert( - { aHash, std::make_pair(NUMBER_OF_UNSHARED_INSTANCES, nullptr) }); + { rItem.ItemType(), std::make_pair(NUMBER_OF_UNSHARED_INSTANCES, nullptr) }); return nullptr; } @@ -195,7 +194,7 @@ public: // here the countdown is zero and there is not yet a ItemInstanceManager // incarnated. Do so, register and return it assert(nullptr == aHit->second.second); - DefaultItemInstanceManager* pNew(new DefaultItemInstanceManager(aHash)); + DefaultItemInstanceManager* pNew(new DefaultItemInstanceManager(rItem.ItemType())); aHit->second.second = pNew; return pNew; @@ -216,15 +215,14 @@ public: // hopefully fastest) incarnations ItemInstanceManager* pManager(rItem.getItemInstanceManager()); - // Check for correct hash, there may be derivations of that class. + // Check for correct SfxItemType, there may be derivations of that class. // Note that Managers from the Items are *not* added to local list, // they are expected to be static instances at the Items - const std::size_t aHash(typeid(rItem).hash_code()); - if (nullptr != pManager && pManager->getClassHash() == aHash) + if (nullptr != pManager && pManager->ItemType() == rItem.ItemType()) return pManager; // check local memory for existing entry - managerTypeMap::iterator aHit(maManagerPerType.find(aHash)); + managerTypeMap::iterator aHit(maManagerPerType.find(rItem.ItemType())); if (aHit == maManagerPerType.end()) // no instance yet, return nullptr |