summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qhash.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-01-22 15:05:38 +0100
committerLars Knoll <lars.knoll@qt.io>2020-04-09 20:03:11 +0200
commit3b4662794234e2f0c5b343f83f6f3b37fc236a25 (patch)
tree3fb7ea83d81635709859a6492d900a4907a82257 /src/corelib/tools/qhash.h
parente1e573cee8f0197a1549929dc9e818f8004fb1cb (diff)
Optimize QHash when using QHashDummyValue
This is used by QSet to avoid storing extra data for the value in the Hash. Re-implement the optimization after the changes to QHash. Change-Id: Ic7eba53d1c0398399ed5b25fef589ad62567445f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r--src/corelib/tools/qhash.h29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 09d7ade20f..d5d13f7bf3 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -107,6 +107,31 @@ struct Node
{
return std::move(value);
}
+ bool valuesEqual(const Node *other) const { return value == other->value; }
+};
+
+template <typename Key>
+struct Node<Key, QHashDummyValue> {
+ using KeyType = Key;
+ using ValueType = QHashDummyValue;
+
+ Key key;
+ static Node create(Key &&k, ValueType &&)
+ {
+ return Node{ std::move(k) };
+ }
+ static Node create(const Key &k, const ValueType &)
+ {
+ return Node{ k };
+ }
+ void replace(const ValueType &)
+ {
+ }
+ void replace(ValueType &&)
+ {
+ }
+ ValueType takeValue() { return QHashDummyValue(); }
+ bool valuesEqual(const Node *) const { return true; }
};
template <typename T>
@@ -844,7 +869,7 @@ public:
for (const_iterator it = other.begin(); it != other.end(); ++it) {
const_iterator i = find(it.key());
- if (i == end() || !(i.value() == it.value()))
+ if (i == end() || !i.i.node()->valuesEqual(it.i.node()))
return false;
}
// all values must be the same as size is the same
@@ -1156,7 +1181,7 @@ public:
{
detach();
- auto i = d->insert(Node{key, value});
+ auto i = d->insert(Node::create(key, value));
return iterator(i);
}
void insert(const QHash &hash)