Changeset 561 for trunk/src/corelib/tools/qhash.h
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/corelib/tools/qhash.h
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtCore module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 53 53 QT_BEGIN_NAMESPACE 54 54 55 #undef QT_QHASH_DEBUG56 55 QT_MODULE(Core) 57 56 … … 71 70 { 72 71 if (sizeof(ulong) > sizeof(uint)) { 73 return uint(( key >> (8 * sizeof(uint) - 1)) ^ key);72 return uint((); 74 73 } else { 75 return uint(key );74 return uint(key); 76 75 } 77 76 } … … 80 79 { 81 80 if (sizeof(quint64) > sizeof(uint)) { 82 return uint(( key >> (8 * sizeof(uint) - 1)) ^ key);81 return uint((); 83 82 } else { 84 return uint(key );83 return uint(key); 85 84 } 86 85 } … … 98 97 template <class T> inline uint qHash(const T *key) 99 98 { 100 if (sizeof(const T *) > sizeof(uint)) 101 return qHash(reinterpret_cast<quint64>(key)); 102 else 103 return uint(reinterpret_cast<ulong>(key)); 99 return qHash(reinterpret_cast<quintptr>(key)); 104 100 } 105 101 #if defined(Q_CC_MSVC) … … 130 126 int numBuckets; 131 127 uint sharable : 1; 132 133 void *allocateNode(); 128 uint strictAlignment : 1; 129 uint reserved : 30; 130 131 void *allocateNode(); // ### Qt5 remove me 132 void *allocateNode(int nodeAlign); 134 133 void freeNode(void *node); 135 QHashData *detach_helper(void (*node_duplicate)(Node *, void *), int nodeSize); 134 QHashData *detach_helper(void (*node_duplicate)(Node *, void *), int nodeSize); // ### Qt5 remove me 135 QHashData *detach_helper2(void (*node_duplicate)(Node *, void *), void (*node_delete)(Node *), 136 int nodeSize, int nodeAlign); 136 137 void mightGrow(); 137 138 bool willGrow(); 138 139 void hasShrunk(); 139 140 void rehash(int hint); 140 void destroyAndFree(); 141 void free_helper(void (*node_delete)(Node *)); 142 void destroyAndFree(); // ### Qt5 remove me 141 143 Node *firstNode(); 142 144 #ifdef QT_QHASH_DEBUG … … 151 153 152 154 inline void QHashData::mightGrow() // ### Qt 5: eliminate 153 { 155 { 154 156 if (size >= numBuckets) 155 157 rehash(numBits + 1); 156 } 158 } 157 159 158 160 inline bool QHashData::willGrow() … … 168 170 inline void QHashData::hasShrunk() 169 171 { 170 if (size <= (numBuckets >> 3) && numBits > userNumBits) 171 rehash(qMax(int(numBits) - 2, int(userNumBits))); 172 if (size <= (numBuckets >> 3) && numBits > userNumBits) { 173 QT_TRY { 174 rehash(qMax(int(numBits) - 2, int(userNumBits))); 175 } QT_CATCH(const std::bad_alloc &) { 176 // ignore bad allocs - shrinking shouldn't throw. rehash is exception safe. 177 } 178 } 172 179 } 173 180 … … 264 271 } 265 272 273 274 275 276 277 278 279 280 266 281 public: 267 282 inline QHash() : d(&QHashData::shared_null) { d->ref.ref(); } … … 480 495 Node *createNode(uint h, const Key &key, const T &value, Node **nextNode); 481 496 void deleteNode(Node *node); 497 482 498 483 499 static void duplicateNode(QHashData::Node *originalNode, void *newNode); 484 500 }; 485 501 502 486 503 template <class Key, class T> 487 504 Q_INLINE_TEMPLATE void QHash<Key, T>::deleteNode(Node *node) 488 505 { 506 507 508 509 510 511 512 489 513 #ifdef Q_CC_BOR 490 node->~QHashNode<Key, T>();514 ->~QHashNode<Key, T>(); 491 515 #elif defined(QT_NO_PARTIAL_TEMPLATE_SPECIALIZATION) 492 node->~QHashNode();516 ->~QHashNode(); 493 517 #else 494 node->~Node(); 495 #endif 496 d->freeNode(node); 518 concrete(node)->~Node(); 519 #endif 497 520 } 498 521 … … 515 538 516 539 if (QTypeInfo<T>::isDummy) { 517 node = reinterpret_cast<Node *>(new (d->allocateNode( )) DummyNode(akey));540 node = reinterpret_cast<Node *>(new (d->allocateNode()) DummyNode(akey)); 518 541 } else { 519 node = new (d->allocateNode( )) Node(akey, avalue);542 node = new (d->allocateNode()) Node(akey, avalue); 520 543 } 521 544 … … 542 565 Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::freeData(QHashData *x) 543 566 { 544 Node *e_for_x = reinterpret_cast<Node *>(x); 545 Node **bucket = reinterpret_cast<Node **>(x->buckets); 546 int n = x->numBuckets; 547 while (n--) { 548 Node *cur = *bucket++; 549 while (cur != e_for_x) { 550 Node *next = cur->next; 551 deleteNode(cur); 552 cur = next; 553 } 554 } 555 x->destroyAndFree(); 567 x->free_helper(deleteNode2); 556 568 } 557 569 … … 565 577 Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::detach_helper() 566 578 { 567 QHashData *x = d->detach_helper(duplicateNode, 568 QTypeInfo<T>::isDummy ? sizeof(DummyNode) : sizeof(Node)); 579 QHashData *x = d->detach_helper2(duplicateNode, deleteNode2, 580 QTypeInfo<T>::isDummy ? sizeof(DummyNode) : sizeof(Node), 581 QTypeInfo<T>::isDummy ? alignOfDummyNode() : alignOfNode()); 569 582 if (!d->ref.deref()) 570 583 freeData(d); … … 764 777 Q_OUTOFLINE_TEMPLATE int QHash<Key, T>::remove(const Key &akey) 765 778 { 779 780 766 781 detach(); 767 782 … … 785 800 Q_OUTOFLINE_TEMPLATE T QHash<Key, T>::take(const Key &akey) 786 801 { 802 803 787 804 detach(); 788 805 … … 915 932 { QMultiHash result = *this; result += other; return result; } 916 933 917 #ifndef Q_NO_USING_KEYWORD 934 #if !defined(Q_NO_USING_KEYWORD) && !defined(Q_CC_RVCT) 935 // RVCT compiler doesn't handle using-keyword right when used functions are overloaded in child class 918 936 using QHash<Key, T>::contains; 919 937 using QHash<Key, T>::remove; … … 985 1003 while (i != end && i.key() == key) { 986 1004 if (i.value() == value) { 1005 1006 1007 1008 987 1009 i = erase(i); 1010 988 1011 ++n; 989 1012 } else {
Note:
See TracChangeset
for help on using the changeset viewer.