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>
This commit is contained in:
parent
e1e573cee8
commit
3b46627942
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user