diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2022-02-08 11:36:42 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2022-02-08 20:57:41 +0100 |
commit | 98d51bf8ce13bdac2d71f50f58d6d0ddb9041a4f (patch) | |
tree | 354392bc240a1e33a9808fbc6659baa16c3bbefc /svl | |
parent | aaf130beacfda06bcbc305e70030bdf5369e0743 (diff) |
speed up SfxItemPool searches with items that can't use IsSortable()
As pointed out by 585e0ac43b9bd8a2f714903034e435c84ae3fc96, some
item types cannot be used as IsSortable(), because they are modified
after having been inserted in the pool, which breaks the sorted
order. But it's possible to at least somewhat improve performance
of these items by explicitly providing a hash code and using
that first for comparisons when looking up items, which may be
cheaper than calling operator==.
With ScPatternAttr such comparisons seem to take only 60% of the
original time, reducing loading time of some documents by 25%.
Change-Id: I41f4dda472fb6db066742976672f2c08b9aeef63
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129667
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/items/itempool.cxx | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/svl/source/items/itempool.cxx b/svl/source/items/itempool.cxx index 8d4aa074e4f5..acd5c77de452 100644 --- a/svl/source/items/itempool.cxx +++ b/svl/source/items/itempool.cxx @@ -627,12 +627,28 @@ const SfxPoolItem& SfxItemPool::PutImpl( const SfxPoolItem& rItem, sal_uInt16 nW } else { - for (auto itr = rItemArr.begin(); itr != rItemArr.end(); ++itr) + // If the item provides a valid hash, use that to speed up comparisons. + size_t lookupHashCode = rItem.LookupHashCode(); + if (lookupHashCode != 0) { - if (**itr == rItem) + for (auto itr = rItemArr.begin(); itr != rItemArr.end(); ++itr) { - pFoundItem = *itr; - break; + if ((*itr)->LookupHashCode() == lookupHashCode && **itr == rItem) + { + pFoundItem = *itr; + break; + } + } + } + else + { + for (auto itr = rItemArr.begin(); itr != rItemArr.end(); ++itr) + { + if (**itr == rItem) + { + pFoundItem = *itr; + break; + } } } } |