summaryrefslogtreecommitdiff
path: root/include/comphelper
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2022-05-13 15:06:52 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-05-14 19:14:19 +0200
commit22e08a3d8b043ce0ff2424d3fa0a704804afc567 (patch)
tree1ec23cb9304c2b6e074c3adfbdd5bb2873ae3267 /include/comphelper
parent2a274f47ee5759b17ab22497dbe64ef6135d4cd6 (diff)
tdf#121740 cache hashcode in SequenceAsHashMap
shaves 2% off load time Change-Id: I5bd4eabf61205df21a27d2822acd2676a7732a3d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134315 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/comphelper')
-rw-r--r--include/comphelper/sequenceashashmap.hxx39
1 files changed, 38 insertions, 1 deletions
diff --git a/include/comphelper/sequenceashashmap.hxx b/include/comphelper/sequenceashashmap.hxx
index d6bcd77f0d1a..59ab4c298d76 100644
--- a/include/comphelper/sequenceashashmap.hxx
+++ b/include/comphelper/sequenceashashmap.hxx
@@ -39,7 +39,29 @@ namespace comphelper{
such name sequences very easy ...
*/
-using SequenceAsHashMapBase = std::unordered_map<OUString, css::uno::Any>;
+/** Cache the hash code since calculating it for every comparison adds up */
+struct OUStringAndHashCode
+{
+ OUString maString;
+ sal_Int32 mnHashCode;
+
+ OUStringAndHashCode(OUString s) : maString(s), mnHashCode(maString.hashCode()) {}
+};
+struct OUStringAndHashCodeEqual
+{
+ bool operator()(const OUStringAndHashCode & lhs, const OUStringAndHashCode & rhs) const
+ {
+ return lhs.mnHashCode == rhs.mnHashCode && lhs.maString == rhs.maString;
+ }
+};
+struct OUStringAndHashCodeHash
+{
+ size_t operator()(const OUStringAndHashCode & i) const
+ {
+ return i.mnHashCode;
+ }
+};
+using SequenceAsHashMapBase = std::unordered_map<OUStringAndHashCode, css::uno::Any, OUStringAndHashCodeHash, OUStringAndHashCodeEqual>;
class SAL_WARN_UNUSED COMPHELPER_DLLPUBLIC SequenceAsHashMap
{
@@ -320,6 +342,11 @@ class SAL_WARN_UNUSED COMPHELPER_DLLPUBLIC SequenceAsHashMap
return m_aMap[rKey];
}
+ css::uno::Any& operator[](const OUStringAndHashCode& rKey)
+ {
+ return m_aMap[rKey];
+ }
+
using iterator = SequenceAsHashMapBase::iterator;
using const_iterator = SequenceAsHashMapBase::const_iterator;
@@ -368,6 +395,16 @@ class SAL_WARN_UNUSED COMPHELPER_DLLPUBLIC SequenceAsHashMap
return m_aMap.find(rKey);
}
+ iterator find(const OUStringAndHashCode& rKey)
+ {
+ return m_aMap.find(rKey);
+ }
+
+ const_iterator find(const OUStringAndHashCode& rKey) const
+ {
+ return m_aMap.find(rKey);
+ }
+
iterator erase(iterator it)
{
return m_aMap.erase(it);