remove dummy QHash node support

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2019-06-23 14:54:39 +00:00
parent 1dae6e697d
commit 8aa766e084
3 changed files with 13 additions and 57 deletions

View file

@ -1038,8 +1038,7 @@ public:
isPointer = false, isPointer = false,
isComplex = true, isComplex = true,
isStatic = true, isStatic = true,
isLarge = (sizeof(T)>sizeof(void*)), isLarge = (sizeof(T)>sizeof(void*))
isDummy = false
}; };
}; };
@ -1051,8 +1050,7 @@ public:
isPointer = true, isPointer = true,
isComplex = false, isComplex = false,
isStatic = false, isStatic = false,
isLarge = false, isLarge = false
isDummy = false
}; };
}; };
@ -1068,8 +1066,7 @@ enum { /* TYPEINFO flags */
Q_COMPLEX_TYPE = 0, Q_COMPLEX_TYPE = 0,
Q_PRIMITIVE_TYPE = 0x1, Q_PRIMITIVE_TYPE = 0x1,
Q_STATIC_TYPE = 0, Q_STATIC_TYPE = 0,
Q_MOVABLE_TYPE = 0x2, Q_MOVABLE_TYPE = 0x2
Q_DUMMY_TYPE = 0x4
}; };
#define Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS) \ #define Q_DECLARE_TYPEINFO_BODY(TYPE, FLAGS) \
@ -1080,8 +1077,7 @@ public: \
isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \ isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0), \
isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \ isStatic = (((FLAGS) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), \
isLarge = (sizeof(TYPE)>sizeof(void*)), \ isLarge = (sizeof(TYPE)>sizeof(void*)), \
isPointer = false, \ isPointer = false \
isDummy = (((FLAGS) & Q_DUMMY_TYPE) != 0) \
}; \ }; \
static inline const char *name() { return #TYPE; } \ static inline const char *name() { return #TYPE; } \
} }

View file

@ -157,27 +157,6 @@ inline QHashData::Node *QHashData::firstNode()
return e; return e;
} }
struct QHashDummyValue
{
};
inline bool operator==(const QHashDummyValue & /* v1 */, const QHashDummyValue & /* v2 */)
{
return true;
}
Q_DECLARE_TYPEINFO(QHashDummyValue, Q_MOVABLE_TYPE | Q_DUMMY_TYPE);
template <class Key, class T>
struct QHashDummyNode
{
QHashDummyNode *next;
uint h;
Key key;
inline QHashDummyNode(const Key &key0) : key(key0) {}
};
template <class Key, class T> template <class Key, class T>
struct QHashNode struct QHashNode
{ {
@ -192,14 +171,6 @@ struct QHashNode
#define Q_HASH_DECLARE_INT_NODES(key_type) \ #define Q_HASH_DECLARE_INT_NODES(key_type) \
template <class T> \
struct QHashDummyNode<key_type, T> { \
QHashDummyNode *next; \
union { uint h; key_type key; }; \
\
inline QHashDummyNode(key_type /* key0 */) {} \
}; \
\
template <class T> \ template <class T> \
struct QHashNode<key_type, T> { \ struct QHashNode<key_type, T> { \
QHashNode *next; \ QHashNode *next; \
@ -222,7 +193,6 @@ Q_HASH_DECLARE_INT_NODES(uint);
template <class Key, class T> template <class Key, class T>
class QHash class QHash
{ {
typedef QHashDummyNode<Key, T> DummyNode;
typedef QHashNode<Key, T> Node; typedef QHashNode<Key, T> Node;
union { union {
@ -468,11 +438,7 @@ template <class Key, class T>
Q_INLINE_TEMPLATE void QHash<Key, T>::duplicateNode(QHashData::Node *node, void *newNode) Q_INLINE_TEMPLATE void QHash<Key, T>::duplicateNode(QHashData::Node *node, void *newNode)
{ {
Node *concreteNode = concrete(node); Node *concreteNode = concrete(node);
if (QTypeInfo<T>::isDummy) {
(void) new (newNode) DummyNode(concreteNode->key);
} else {
(void) new (newNode) Node(concreteNode->key, concreteNode->value); (void) new (newNode) Node(concreteNode->key, concreteNode->value);
}
} }
template <class Key, class T> template <class Key, class T>
@ -483,11 +449,7 @@ QHash<Key, T>::createNode(uint ah, const Key &akey, const T &avalue, Node **anex
void *nodeptr = malloc(d->nodeSize); void *nodeptr = malloc(d->nodeSize);
Q_CHECK_PTR(nodeptr); Q_CHECK_PTR(nodeptr);
if (QTypeInfo<T>::isDummy) {
node = reinterpret_cast<Node *>(new (nodeptr) DummyNode(akey));
} else {
node = new (nodeptr) Node(akey, avalue); node = new (nodeptr) Node(akey, avalue);
}
node->h = ah; node->h = ah;
node->next = *anextNode; node->next = *anextNode;
@ -523,8 +485,7 @@ Q_INLINE_TEMPLATE void QHash<Key, T>::clear()
template <class Key, class T> template <class Key, class T>
Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::detach_helper() Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::detach_helper()
{ {
QHashData *x = d->detach_helper(duplicateNode, deleteNode2, QHashData *x = d->detach_helper(duplicateNode, deleteNode2, sizeof(Node));
QTypeInfo<T>::isDummy ? sizeof(DummyNode) : sizeof(Node));
if (!d->ref.deref()) if (!d->ref.deref())
freeData(d); freeData(d);
d = x; d = x;
@ -706,7 +667,6 @@ Q_INLINE_TEMPLATE typename QHash<Key, T>::iterator QHash<Key, T>::insert(const K
return iterator(createNode(h, akey, avalue, node)); return iterator(createNode(h, akey, avalue, node));
} }
if (!QTypeInfo<T>::isDummy)
(*node)->value = avalue; (*node)->value = avalue;
return iterator(*node); return iterator(*node);
} }
@ -854,7 +814,7 @@ Q_OUTOFLINE_TEMPLATE bool QHash<Key, T>::operator==(const QHash<Key, T> &other)
do { do {
if (it2 == other.end() || !(it2.key() == akey)) if (it2 == other.end() || !(it2.key() == akey))
return false; return false;
if (!QTypeInfo<T>::isDummy && !(it.value() == it2.value())) if (!(it.value() == it2.value()))
return false; return false;
++it; ++it;
++it2; ++it2;

View file

@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE
template <class T> template <class T>
class QSet class QSet
{ {
typedef QHash<T, QHashDummyValue> Hash; typedef QHash<T, bool> Hash;
public: public:
inline QSet() {} inline QSet() {}
@ -87,7 +87,7 @@ public:
class iterator class iterator
{ {
typedef QHash<T, QHashDummyValue> Hash; typedef QHash<T, bool> Hash;
typename Hash::iterator i; typename Hash::iterator i;
friend class const_iterator; friend class const_iterator;
@ -122,7 +122,7 @@ public:
class const_iterator class const_iterator
{ {
typedef QHash<T, QHashDummyValue> Hash; typedef QHash<T, bool> Hash;
typename Hash::const_iterator i; typename Hash::const_iterator i;
friend class iterator; friend class iterator;
@ -168,7 +168,7 @@ public:
typedef const_iterator ConstIterator; typedef const_iterator ConstIterator;
inline int count() const { return q_hash.count(); } inline int count() const { return q_hash.count(); }
inline iterator insert(const T &value) inline iterator insert(const T &value)
{ return static_cast<typename Hash::iterator>(q_hash.insert(value, QHashDummyValue())); } { return static_cast<typename Hash::iterator>(q_hash.insert(value, false)); }
iterator find(const T &value) { return q_hash.find(value); } iterator find(const T &value) { return q_hash.find(value); }
const_iterator find(const T &value) const { return q_hash.find(value); } const_iterator find(const T &value) const { return q_hash.find(value); }
inline const_iterator constFind(const T &value) const { return find(value); } inline const_iterator constFind(const T &value) const { return find(value); }