Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/corelib/tools/qhash.h

    r2 r561  
    22**
    33** 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])
    56**
    67** This file is part of the QtCore module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5353QT_BEGIN_NAMESPACE
    5454
    55 #undef QT_QHASH_DEBUG
    5655QT_MODULE(Core)
    5756
     
    7170{
    7271    if (sizeof(ulong) > sizeof(uint)) {
    73         return uint((key >> (8 * sizeof(uint) - 1)) ^ key);
     72        return uint(();
    7473    } else {
    75         return uint(key);
     74        return uint(key);
    7675    }
    7776}
     
    8079{
    8180    if (sizeof(quint64) > sizeof(uint)) {
    82         return uint((key >> (8 * sizeof(uint) - 1)) ^ key);
     81        return uint(();
    8382    } else {
    84         return uint(key);
     83        return uint(key);
    8584    }
    8685}
     
    9897template <class T> inline uint qHash(const T *key)
    9998{
    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));
    104100}
    105101#if defined(Q_CC_MSVC)
     
    130126    int numBuckets;
    131127    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);
    134133    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);
    136137    void mightGrow();
    137138    bool willGrow();
    138139    void hasShrunk();
    139140    void rehash(int hint);
    140     void destroyAndFree();
     141    void free_helper(void (*node_delete)(Node *));
     142    void destroyAndFree(); // ### Qt5 remove me
    141143    Node *firstNode();
    142144#ifdef QT_QHASH_DEBUG
     
    151153
    152154inline void QHashData::mightGrow() // ### Qt 5: eliminate
    153 { 
     155{
    154156    if (size >= numBuckets)
    155157        rehash(numBits + 1);
    156 } 
     158}
    157159
    158160inline bool QHashData::willGrow()
     
    168170inline void QHashData::hasShrunk()
    169171{
    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    }
    172179}
    173180
     
    264271    }
    265272
     273
     274
     275
     276
     277
     278
     279
     280
    266281public:
    267282    inline QHash() : d(&QHashData::shared_null) { d->ref.ref(); }
     
    480495    Node *createNode(uint h, const Key &key, const T &value, Node **nextNode);
    481496    void deleteNode(Node *node);
     497
    482498
    483499    static void duplicateNode(QHashData::Node *originalNode, void *newNode);
    484500};
    485501
     502
    486503template <class Key, class T>
    487504Q_INLINE_TEMPLATE void QHash<Key, T>::deleteNode(Node *node)
    488505{
     506
     507
     508
     509
     510
     511
     512
    489513#ifdef Q_CC_BOR
    490     node->~QHashNode<Key, T>();
     514    ->~QHashNode<Key, T>();
    491515#elif defined(QT_NO_PARTIAL_TEMPLATE_SPECIALIZATION)
    492     node->~QHashNode();
     516    ->~QHashNode();
    493517#else
    494     node->~Node();
    495 #endif
    496     d->freeNode(node);
     518    concrete(node)->~Node();
     519#endif
    497520}
    498521
     
    515538
    516539    if (QTypeInfo<T>::isDummy) {
    517         node = reinterpret_cast<Node *>(new (d->allocateNode()) DummyNode(akey));
     540        node = reinterpret_cast<Node *>(new (d->allocateNode()) DummyNode(akey));
    518541    } else {
    519         node = new (d->allocateNode()) Node(akey, avalue);
     542        node = new (d->allocateNode()) Node(akey, avalue);
    520543    }
    521544
     
    542565Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::freeData(QHashData *x)
    543566{
    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);
    556568}
    557569
     
    565577Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::detach_helper()
    566578{
    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());
    569582    if (!d->ref.deref())
    570583        freeData(d);
     
    764777Q_OUTOFLINE_TEMPLATE int QHash<Key, T>::remove(const Key &akey)
    765778{
     779
     780
    766781    detach();
    767782
     
    785800Q_OUTOFLINE_TEMPLATE T QHash<Key, T>::take(const Key &akey)
    786801{
     802
     803
    787804    detach();
    788805
     
    915932    { QMultiHash result = *this; result += other; return result; }
    916933
    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
    918936    using QHash<Key, T>::contains;
    919937    using QHash<Key, T>::remove;
     
    9851003    while (i != end && i.key() == key) {
    9861004        if (i.value() == value) {
     1005
     1006
     1007
     1008
    9871009            i = erase(i);
     1010
    9881011            ++n;
    9891012        } else {
Note: See TracChangeset for help on using the changeset viewer.