qhash.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qhash.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15-
16-
17static inline bool hasFastCrc32()-
18{-
19 return ((qCompilerCpuFeatures & (static_cast<unsigned long long>(1ULL) << CpuFeatureSSE4_2)) || (qCpuFeatures() & (static_cast<unsigned long long>(1ULL) << CpuFeatureSSE4_2)));-
20}-
21-
22template <typename Char>-
23__attribute__((__target__("sse4.2")))-
24static uint crc32(const Char *ptr, size_t len, uint h)-
25{-
26-
27 const uchar *p = reinterpret_cast<const uchar *>(ptr);-
28 const uchar *const e = p + (len * sizeof(Char));-
29-
30-
31-
32 qulonglong h2 = h;-
33-
34 p += 8;-
35 for ( ; p <= e; p += 8)-
36 h2 = _mm_crc32_u64(h2, qFromUnaligned<qlonglong>(p - 8));-
37 h = h2;-
38 p -= 8;-
39-
40 len = e - p;-
41 if (len & 4) {-
42 h = _mm_crc32_u32(h, qFromUnaligned<uint>(p));-
43 p += 4;-
44 }-
45-
46-
47-
48-
49-
50-
51-
52 if (len & 2) {-
53 h = _mm_crc32_u16(h, qFromUnaligned<ushort>(p));-
54 p += 2;-
55 }-
56 if (sizeof(Char) == 1 && len & 1)-
57 h = _mm_crc32_u8(h, *p);-
58 return h;-
59}-
60static inline uint hash(const uchar *p, int len, uint seed) noexcept-
61{-
62 uint h = seed;-
63-
64 if (hasFastCrc32()
hasFastCrc32()Description
TRUEevaluated 145634 times by 401 tests
Evaluated by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QAnimationGroup
  • tst_QApplication
  • tst_QAuthenticator
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QClipboard
  • tst_QColorDialog
  • tst_QColumnView
  • ...
FALSEnever evaluated
)
0-145634
65 return
executed 145634 times by 401 tests: return crc32(p, size_t(len), h);
Executed by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QAnimationGroup
  • tst_QApplication
  • tst_QAuthenticator
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QClipboard
  • tst_QColorDialog
  • tst_QColumnView
  • ...
crc32(p, size_t(len), h);
executed 145634 times by 401 tests: return crc32(p, size_t(len), h);
Executed by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QAnimationGroup
  • tst_QApplication
  • tst_QAuthenticator
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QClipboard
  • tst_QColorDialog
  • tst_QColumnView
  • ...
145634
66-
67 for (int i = 0; i < len
i < lenDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
68 h = 31 * h + p[i];
never executed: h = 31 * h + p[i];
0
69-
70 return
never executed: return h;
h;
never executed: return h;
0
71}-
72-
73uint qHashBits(const void *p, size_t len, uint seed) noexcept-
74{-
75 return
executed 10 times by 1 test: return hash(static_cast<const uchar*>(p), int(len), seed);
Executed by:
  • tst_QHostAddress
hash(static_cast<const uchar*>(p), int(len), seed);
executed 10 times by 1 test: return hash(static_cast<const uchar*>(p), int(len), seed);
Executed by:
  • tst_QHostAddress
10
76}-
77-
78static inline uint hash(const QChar *p, int len, uint seed) noexcept-
79{-
80 uint h = seed;-
81-
82 if (hasFastCrc32()
hasFastCrc32()Description
TRUEevaluated 2392194 times by 441 tests
Evaluated by:
  • tst_Collections
  • tst_Gestures
  • tst_Lancelot
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractButton
  • tst_QAbstractFileEngine
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QAuthenticator
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QBrush
  • tst_QButtonGroup
  • ...
FALSEnever evaluated
)
0-2392194
83 return
executed 2392194 times by 441 tests: return crc32(p, size_t(len), h);
Executed by:
  • tst_Collections
  • tst_Gestures
  • tst_Lancelot
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractButton
  • tst_QAbstractFileEngine
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QAuthenticator
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QBrush
  • tst_QButtonGroup
  • ...
crc32(p, size_t(len), h);
executed 2392194 times by 441 tests: return crc32(p, size_t(len), h);
Executed by:
  • tst_Collections
  • tst_Gestures
  • tst_Lancelot
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractButton
  • tst_QAbstractFileEngine
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QAuthenticator
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QBrush
  • tst_QButtonGroup
  • ...
2392194
84-
85 for (int i = 0; i < len
i < lenDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
86 h = 31 * h + p[i].unicode();
never executed: h = 31 * h + p[i].unicode();
0
87-
88 return
never executed: return h;
h;
never executed: return h;
0
89}-
90-
91uint qHash(const QByteArray &key, uint seed) noexcept-
92{-
93 return
executed 110206 times by 397 tests: return hash(reinterpret_cast<const uchar *>(key.constData()), key.size(), seed);
Executed by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QAnimationGroup
  • tst_QApplication
  • tst_QAuthenticator
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QClipboard
  • tst_QColorDialog
  • tst_QColumnView
  • ...
hash(reinterpret_cast<const uchar *>(key.constData()), key.size(), seed);
executed 110206 times by 397 tests: return hash(reinterpret_cast<const uchar *>(key.constData()), key.size(), seed);
Executed by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QAnimationGroup
  • tst_QApplication
  • tst_QAuthenticator
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QByteArray
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QClipboard
  • tst_QColorDialog
  • tst_QColumnView
  • ...
110206
94}-
95-
96uint qHash(const QString &key, uint seed) noexcept-
97{-
98 return
executed 2392182 times by 441 tests: return hash(key.unicode(), key.size(), seed);
Executed by:
  • tst_Collections
  • tst_Gestures
  • tst_Lancelot
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractButton
  • tst_QAbstractFileEngine
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QAuthenticator
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QBrush
  • tst_QButtonGroup
  • ...
hash(key.unicode(), key.size(), seed);
executed 2392182 times by 441 tests: return hash(key.unicode(), key.size(), seed);
Executed by:
  • tst_Collections
  • tst_Gestures
  • tst_Lancelot
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_PlatformSocketEngine
  • tst_QAbstractButton
  • tst_QAbstractFileEngine
  • tst_QAbstractItemModel
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractPrintDialog
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QAuthenticator
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QBrush
  • tst_QButtonGroup
  • ...
2392182
99}-
100-
101uint qHash(const QStringRef &key, uint seed) noexcept-
102{-
103 return
executed 12 times by 1 test: return hash(key.unicode(), key.size(), seed);
Executed by:
  • tst_QString
hash(key.unicode(), key.size(), seed);
executed 12 times by 1 test: return hash(key.unicode(), key.size(), seed);
Executed by:
  • tst_QString
12
104}-
105-
106uint qHash(const QBitArray &bitArray, uint seed) noexcept-
107{-
108 int m = bitArray.d.size() - 1;-
109 uint result = hash(reinterpret_cast<const uchar *>(bitArray.d.constData()), qMax(0, m), seed);-
110-
111-
112-
113 int n = bitArray.size();-
114 if (n & 0x7
n & 0x7Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • tst_QHashFunctions
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QHashFunctions
)
1-9
115 result = ((result << 4) + bitArray.d.at(m)) & ((1 << n) - 1);
executed 9 times by 1 test: result = ((result << 4) + bitArray.d.at(m)) & ((1 << n) - 1);
Executed by:
  • tst_QHashFunctions
9
116 return
executed 10 times by 1 test: return result;
Executed by:
  • tst_QHashFunctions
result;
executed 10 times by 1 test: return result;
Executed by:
  • tst_QHashFunctions
10
117}-
118-
119uint qHash(QLatin1String key, uint seed) noexcept-
120{-
121 return
executed 18091 times by 1 test: return hash(reinterpret_cast<const uchar *>(key.data()), key.size(), seed);
Executed by:
  • tst_qdbuscpp2xml - unknown status
hash(reinterpret_cast<const uchar *>(key.data()), key.size(), seed);
executed 18091 times by 1 test: return hash(reinterpret_cast<const uchar *>(key.data()), key.size(), seed);
Executed by:
  • tst_qdbuscpp2xml - unknown status
18091
122}-
123static uint qt_create_qhash_seed()-
124{-
125 uint seed = 0;-
126-
127-
128 QByteArray envSeed = qgetenv("QT_HASH_SEED");-
129 if (!envSeed.isNull())-
130 return envSeed.toUInt();-
131-
132-
133 int randomfd = qt_safe_open("/dev/urandom", 00);-
134 if (randomfd == -1)-
135 randomfd = qt_safe_open("/dev/random", 00 | 04000);-
136 if (randomfd != -1) {-
137 if (qt_safe_read(randomfd, reinterpret_cast<char *>(&seed), sizeof(seed)) == sizeof(seed)) {-
138 qt_safe_close(randomfd);-
139 return seed;-
140 }-
141 qt_safe_close(randomfd);-
142 }-
143 quint64 timestamp = QDateTime::currentMSecsSinceEpoch();-
144 seed ^= timestamp;-
145 seed ^= (timestamp >> 32);-
146-
147 quint64 pid = QCoreApplication::applicationPid();-
148 seed ^= pid;-
149 seed ^= (pid >> 32);-
150-
151 quintptr seedPtr = reinterpret_cast<quintptr>(&seed);-
152 seed ^= seedPtr;-
153 seed ^= (qulonglong(seedPtr) >> 32);-
154-
155-
156 return seed;-
157}-
158-
159-
160-
161-
162__attribute__((visibility("default"))) QBasicAtomicInt qt_qhash_seed = { -1 };-
163static void qt_initialize_qhash_seed()-
164{-
165 if (qt_qhash_seed.load() == -1) {-
166 int x(qt_create_qhash_seed() & 2147483647);-
167 qt_qhash_seed.testAndSetRelaxed(-1, x);-
168 }-
169}-
170int qGlobalQHashSeed()-
171{-
172 return qt_qhash_seed.load();-
173}-
174void qSetGlobalQHashSeed(int newSeed)-
175{-
176 if (qEnvironmentVariableIsSet("QT_HASH_SEED"))-
177 return;-
178 if (newSeed == -1) {-
179 int x(qt_create_qhash_seed() & 2147483647);-
180 qt_qhash_seed.store(x);-
181 } else {-
182 qt_qhash_seed.store(newSeed & 2147483647);-
183 }-
184}-
185static uint qt_hash(const QChar *p, int n) noexcept-
186{-
187 uint h = 0;-
188-
189 while (n--
n--Description
TRUEevaluated 1730761 times by 116 tests
Evaluated by:
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • tst_QDBusConnection_Delayed
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDir
  • tst_QDirIterator
  • tst_QDnsLookup_Appless
  • tst_QDoubleSpinBox
  • tst_QErrorMessage
  • tst_QFile
  • ...
FALSEevaluated 171327 times by 116 tests
Evaluated by:
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • tst_QDBusConnection_Delayed
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDir
  • tst_QDirIterator
  • tst_QDnsLookup_Appless
  • tst_QDoubleSpinBox
  • tst_QErrorMessage
  • tst_QFile
  • ...
) {
171327-1730761
190 h = (h << 4) + (*p++).unicode();-
191 h ^= (h & 0xf0000000) >> 23;-
192 h &= 0x0fffffff;-
193 }
executed 1730761 times by 116 tests: end of block
Executed by:
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • tst_QDBusConnection_Delayed
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDir
  • tst_QDirIterator
  • tst_QDnsLookup_Appless
  • tst_QDoubleSpinBox
  • tst_QErrorMessage
  • tst_QFile
  • ...
1730761
194 return
executed 171327 times by 116 tests: return h;
Executed by:
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • tst_QDBusConnection_Delayed
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDir
  • tst_QDirIterator
  • tst_QDnsLookup_Appless
  • tst_QDoubleSpinBox
  • tst_QErrorMessage
  • tst_QFile
  • ...
h;
executed 171327 times by 116 tests: return h;
Executed by:
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • tst_QDBusConnection_Delayed
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDir
  • tst_QDirIterator
  • tst_QDnsLookup_Appless
  • tst_QDoubleSpinBox
  • tst_QErrorMessage
  • tst_QFile
  • ...
171327
195}-
196-
197-
198-
199-
200-
201uint qt_hash(const QString &key) noexcept-
202{-
203 return
executed 5 times by 1 test: return qt_hash(key.unicode(), key.size());
Executed by:
  • tst_QHashFunctions
qt_hash(key.unicode(), key.size());
executed 5 times by 1 test: return qt_hash(key.unicode(), key.size());
Executed by:
  • tst_QHashFunctions
5
204}-
205-
206-
207-
208-
209-
210uint qt_hash(const QStringRef &key) noexcept-
211{-
212 return
executed 171322 times by 115 tests: return qt_hash(key.unicode(), key.size());
Executed by:
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • tst_QDBusConnection_Delayed
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDir
  • tst_QDirIterator
  • tst_QDnsLookup_Appless
  • tst_QDoubleSpinBox
  • tst_QErrorMessage
  • tst_QFile
  • ...
qt_hash(key.unicode(), key.size());
executed 171322 times by 115 tests: return qt_hash(key.unicode(), key.size());
Executed by:
  • tst_QAbstractFileEngine
  • tst_QAbstractItemView
  • tst_QAbstractScrollArea
  • tst_QAccessibility
  • tst_QApplication
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLineParser
  • tst_QCommandLinkButton
  • tst_QCompleter
  • tst_QCoreApplication
  • tst_QDBusConnectionNoBus
  • tst_QDBusConnectionNoLibDBus1
  • tst_QDBusConnection_Delayed
  • tst_QDateTimeEdit
  • tst_QDialog
  • tst_QDir
  • tst_QDirIterator
  • tst_QDnsLookup_Appless
  • tst_QDoubleSpinBox
  • tst_QErrorMessage
  • tst_QFile
  • ...
171322
213}-
214static const uchar prime_deltas[] = {-
215 0, 0, 1, 3, 1, 5, 3, 3, 1, 9, 7, 5, 3, 17, 27, 3,-
216 1, 29, 3, 21, 7, 17, 15, 9, 43, 35, 15, 0, 0, 0, 0, 0-
217};-
218-
219-
220-
221-
222-
223-
224static inline int primeForNumBits(int numBits)-
225{-
226 return (1 << numBits) + prime_deltas[numBits];-
227}-
228-
229-
230-
231-
232-
233static int countBits(int hint)-
234{-
235 int numBits = 0;-
236 int bits = hint;-
237-
238 while (bits > 1) {-
239 bits >>= 1;-
240 numBits++;-
241 }-
242-
243 if (numBits >= (int)sizeof(prime_deltas)) {-
244 numBits = sizeof(prime_deltas) - 1;-
245 } else if (primeForNumBits(numBits) < hint) {-
246 ++numBits;-
247 }-
248 return numBits;-
249}-
250-
251-
252-
253-
254-
255const int MinNumBits = 4;-
256-
257const QHashData QHashData::shared_null = {-
258 0, 0, { { -1 } }, 0, 0, MinNumBits, 0, 0, 0, true, false, 0-
259};-
260-
261void *QHashData::allocateNode(int nodeAlign)-
262{-
263 void *ptr = strictAlignment ? qMallocAligned(nodeSize, nodeAlign) : malloc(nodeSize);-
264 do { if (!(ptr)) qBadAlloc(); } while (0);-
265 return ptr;-
266}-
267-
268void QHashData::freeNode(void *node)-
269{-
270 if (strictAlignment)-
271 qFreeAligned(node);-
272 else-
273 free(node);-
274}-
275-
276QHashData *QHashData::detach_helper(void (*node_duplicate)(Node *, void *),-
277 void (*node_delete)(Node *),-
278 int nodeSize,-
279 int nodeAlign)-
280{-
281 union {-
282 QHashData *d;-
283 Node *e;-
284 };-
285 if (this == &shared_null)-
286 qt_initialize_qhash_seed();-
287 d = new QHashData;-
288 d->fakeNext = 0;-
289 d->buckets = 0;-
290 d->ref.initializeOwned();-
291 d->size = size;-
292 d->nodeSize = nodeSize;-
293 d->userNumBits = userNumBits;-
294 d->numBits = numBits;-
295 d->numBuckets = numBuckets;-
296 d->seed = (this == &shared_null) ? uint(qt_qhash_seed.load()) : seed;-
297 d->sharable = true;-
298 d->strictAlignment = nodeAlign > 8;-
299 d->reserved = 0;-
300-
301 if (numBuckets) {-
302 try {-
303 d->buckets = new Node *[numBuckets];-
304 } catch (...) {-
305-
306 d->numBuckets = 0;-
307-
308 d->free_helper(node_delete);-
309 throw;-
310 }-
311-
312 Node *this_e = reinterpret_cast<Node *>(this);-
313 for (int i = 0; i < numBuckets; ++i) {-
314 Node **nextNode = &d->buckets[i];-
315 Node *oldNode = buckets[i];-
316 while (oldNode != this_e) {-
317 try {-
318 Node *dup = static_cast<Node *>(allocateNode(nodeAlign));-
319-
320 try {-
321 node_duplicate(oldNode, dup);-
322 } catch (...) {-
323 freeNode( dup );-
324 throw;-
325 }-
326-
327 *nextNode = dup;-
328 nextNode = &dup->next;-
329 oldNode = oldNode->next;-
330 } catch (...) {-
331-
332 *nextNode = e;-
333 d->numBuckets = i+1;-
334-
335 d->free_helper(node_delete);-
336 throw;-
337 }-
338 }-
339 *nextNode = e;-
340 }-
341 }-
342 return d;-
343}-
344-
345void QHashData::free_helper(void (*node_delete)(Node *))-
346{-
347 if (node_delete) {-
348 Node *this_e = reinterpret_cast<Node *>(this);-
349 Node **bucket = reinterpret_cast<Node **>(this->buckets);-
350-
351 int n = numBuckets;-
352 while (n--) {-
353 Node *cur = *bucket++;-
354 while (cur != this_e) {-
355 Node *next = cur->next;-
356 node_delete(cur);-
357 freeNode(cur);-
358 cur = next;-
359 }-
360 }-
361 }-
362 delete [] buckets;-
363 delete this;-
364}-
365-
366QHashData::Node *QHashData::nextNode(Node *node)-
367{-
368 union {-
369 Node *next;-
370 Node *e;-
371 QHashData *d;-
372 };-
373 next = node->next;-
374 ((!(next)) ? qt_assert_x("QHash", "Iterating beyond end()",__FILE__,556612) : qt_noop());-
375 if (next->next)-
376 return next;-
377-
378 int start = (node->h % d->numBuckets) + 1;-
379 Node **bucket = d->buckets + start;-
380 int n = d->numBuckets - start;-
381 while (n--) {-
382 if (*bucket != e)-
383 return *bucket;-
384 ++bucket;-
385 }-
386 return e;-
387}-
388-
389QHashData::Node *QHashData::previousNode(Node *node)-
390{-
391 union {-
392 Node *e;-
393 QHashData *d;-
394 };-
395-
396 e = node;-
397 while (e->next)-
398 e = e->next;-
399-
400 int start;-
401 if (node == e)-
402 start = d->numBuckets - 1;-
403 else-
404 start = node->h % d->numBuckets;-
405-
406 Node *sentinel = node;-
407 Node **bucket = d->buckets + start;-
408 while (start >= 0) {-
409 if (*bucket != sentinel) {-
410 Node *prev = *bucket;-
411 while (prev->next != sentinel)-
412 prev = prev->next;-
413 return prev;-
414 }-
415-
416 sentinel = e;-
417 --bucket;-
418 --start;-
419 }-
420 ((!(start >= 0)) ? qt_assert_x("QHash", "Iterating backward beyond begin()",__FILE__,602658) : qt_noop());-
421 return e;-
422}-
423-
424-
425-
426-
427-
428-
429-
430void QHashData::rehash(int hint)-
431{-
432 if (hint < 0) {-
433 hint = countBits(-hint);-
434 if (hint < MinNumBits)-
435 hint = MinNumBits;-
436 userNumBits = hint;-
437 while (primeForNumBits(hint) < (size >> 1))-
438 ++hint;-
439 } else if (hint < MinNumBits) {-
440 hint = MinNumBits;-
441 }-
442-
443 if (numBits != hint) {-
444 Node *e = reinterpret_cast<Node *>(this);-
445 Node **oldBuckets = buckets;-
446 int oldNumBuckets = numBuckets;-
447-
448 int nb = primeForNumBits(hint);-
449 buckets = new Node *[nb];-
450 numBits = hint;-
451 numBuckets = nb;-
452 for (int i = 0; i < numBuckets; ++i)-
453 buckets[i] = e;-
454-
455 for (int i = 0; i < oldNumBuckets; ++i) {-
456 Node *firstNode = oldBuckets[i];-
457 while (firstNode != e) {-
458 uint h = firstNode->h;-
459 Node *lastNode = firstNode;-
460 while (lastNode->next != e && lastNode->next->h == h)-
461 lastNode = lastNode->next;-
462-
463 Node *afterLastNode = lastNode->next;-
464 Node **beforeFirstNode = &buckets[h % numBuckets];-
465 while (*beforeFirstNode != e)-
466 beforeFirstNode = &(*beforeFirstNode)->next;-
467 lastNode->next = *beforeFirstNode;-
468 *beforeFirstNode = firstNode;-
469 firstNode = afterLastNode;-
470 }-
471 }-
472 delete [] oldBuckets;-
473 }-
474}-
475uint qHash(float key, uint seed) noexcept-
476{-
477 return
executed 2 times by 1 test: return key != 0.0f ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ;
Executed by:
  • tst_QHashFunctions
key != 0.0f ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ;
executed 2 times by 1 test: return key != 0.0f ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ;
Executed by:
  • tst_QHashFunctions
2
478}-
479-
480-
481-
482-
483-
484-
485uint qHash(double key, uint seed) noexcept-
486{-
487 return
executed 19289 times by 40 tests: return key != 0.0 ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ;
Executed by:
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QApplication
  • tst_QCompleter
  • tst_QDataWidgetMapper
  • tst_QErrorMessage
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsView
  • tst_QHashFunctions
  • tst_QItemDelegate
  • tst_QLabel
  • tst_QMainWindow
  • tst_QMdiArea
  • tst_QMdiSubWindow
  • tst_QMessageBox
  • tst_QPlainTextEdit
  • tst_QShortcut
  • tst_QSplitter
  • tst_QStateMachine
  • tst_QStaticText
  • tst_QStyleSheetStyle
  • tst_QSyntaxHighlighter
  • tst_QTableView
  • ...
key != 0.0 ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ;
executed 19289 times by 40 tests: return key != 0.0 ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ;
Executed by:
  • tst_QAbstractTextDocumentLayout
  • tst_QAccessibility
  • tst_QApplication
  • tst_QCompleter
  • tst_QDataWidgetMapper
  • tst_QErrorMessage
  • tst_QGraphicsItem
  • tst_QGraphicsProxyWidget
  • tst_QGraphicsScene
  • tst_QGraphicsView
  • tst_QHashFunctions
  • tst_QItemDelegate
  • tst_QLabel
  • tst_QMainWindow
  • tst_QMdiArea
  • tst_QMdiSubWindow
  • tst_QMessageBox
  • tst_QPlainTextEdit
  • tst_QShortcut
  • tst_QSplitter
  • tst_QStateMachine
  • tst_QStaticText
  • tst_QStyleSheetStyle
  • tst_QSyntaxHighlighter
  • tst_QTableView
  • ...
19289
488}-
489-
490-
491-
492-
493-
494-
495-
496uint qHash(long double key, uint seed) noexcept-
497{-
498 return
executed 2 times by 1 test: return key != 0.0L ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ;
Executed by:
  • tst_QHashFunctions
key != 0.0L ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ;
executed 2 times by 1 test: return key != 0.0L ? hash(reinterpret_cast<const uchar *>(&key), sizeof(key), seed) : seed ;
Executed by:
  • tst_QHashFunctions
2
499}-
500-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9