summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qhash.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Add qHash(QHash) and qHash(QMultiHash)Marc Mutz2016-07-141-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | The hash function is carefully designed to give the same result as the straight-forward implementation of qHash(unordered_map), which we'll probably add at some point, namely: std::accumulate over a container of std::pair. This is one reason to use std:: and not QPair in the implemen- tation of qHash(QHash). The other is that qHash(QPair) uses a bad hash combiner, which may xor out the 'seed' from the result. We can't fix that until Qt 6, but the qHash(std::pair) overload uses the well-known boost::hash_combine algorithm (implemented in Qt as QtPrivate::QHashCombine), so we can use that. I also trust std::pair to work without problems with reference template arguments, while QPair only very recently gained a very basic auto-test for reference parameters. [ChangeLog][QtCore] Added qHash() overloads for QHash, QMultiHash. Change-Id: I90879d8a99cf1aadb6e84ecc0c3704f52f3691da Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.6' into 5.7Liang Qi2016-06-061-4/+5
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: .qmake.conf config.tests/unix/nis/nis.cpp mkspecs/unsupported/freebsd-g++/qplatformdefs.h src/corelib/tools/qdatetime.cpp src/corelib/tools/qsimd.cpp src/corelib/tools/qsimd_p.h src/network/access/access.pri src/network/access/qnetworkreplynsurlconnectionimpl.mm src/network/access/qnetworkreplynsurlconnectionimpl_p.h src/plugins/platforms/cocoa/qnsview.mm src/plugins/printsupport/windows/qwindowsprintdevice.cpp tests/auto/corelib/kernel/qobject/tst_qobject.cpp tests/auto/network/access/qnetworkreply/BLACKLIST tests/auto/widgets/widgets/qopenglwidget/BLACKLIST Change-Id: I4b32055bbf922392ef0264fd403405416fffee57
| * Replace qUnaligned{Load,Store} with the existing q{To,From}Unalignedv5.6.1-1v5.6.1Thiago Macieira2016-05-251-4/+5
| | | | | | | | | | | | | | | | Move the Q_ALWAYS_INLINE and forcing of __builtin_memcpy to the existing functions. Change-Id: Icaa7fb2a490246bda156ffff143c137e520eea79 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* | Merge remote-tracking branch 'origin/5.6' into 5.7Liang Qi2016-04-071-1/+0
|\| | | | | | | | | | | | | | | | | | | Conflicts: src/network/access/qftp.cpp src/widgets/itemviews/qheaderview.cpp src/widgets/itemviews/qlistview.cpp tests/auto/network/access/qftp/tst_qftp.cpp Change-Id: I9f928f25d45d8944dd60bb583f649fc1615bc5d9
| * Remove empty first lines of files.Friedemann Kleint2016-04-061-1/+0
| | | | | | | | | | | | | | They might upset licensing related tools. Change-Id: I858d21fc418ba16959c88847b559b11bea29ed6b Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* | Merge remote-tracking branch 'origin/5.6' into 5.7Liang Qi2016-03-111-4/+4
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change partially reverts 1bfc7f68 about QT_HAS_BUILTIN define and undef in src/corelib/tools/qsimd_p.h. This change is also squashed with "Fall back to c++11 standard compiler flag for host builds" which is done by Peter Seiderer. Conflicts: mkspecs/features/default_post.prf src/3rdparty/sqlite/0001-Fixing-the-SQLite3-build-for-WEC2013-again.patch src/3rdparty/sqlite/sqlite3.c src/corelib/tools/qsimd_p.h src/gui/kernel/qevent.cpp src/gui/kernel/qwindowsysteminterface.cpp src/gui/kernel/qwindowsysteminterface_p.h src/plugins/bearer/blackberry/blackberry.pro src/plugins/platforms/cocoa/qcocoasystemsettings.mm src/plugins/platformthemes/gtk2/gtk2.pro src/plugins/styles/bb10style/bb10style.pro src/sql/drivers/sqlite2/qsql_sqlite2.cpp tools/configure/configureapp.cpp Task-number: QTBUG-51644 Done-with: Peter Seiderer <ps.report@gmx.net> Change-Id: I6100d6ace31b2e8d41a95f0b5d5ebf8f1fd88b44
| * QString, QJson, QHash: Fix UBs involving unaligned loadsMarc Mutz2016-03-091-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Found by UBSan: src/corelib/tools/qstring.cpp:587:42: runtime error: load of misaligned address 0x2acbf4b7551b for type 'const long long int', which requires 8 byte alignment src/corelib/json/qjson_p.h:405:30: runtime error: store to misaligned address 0x0000019b1e52 for type 'quint64', which requires 8 byte alignment src/corelib/tools/qhash.cpp:116:27: runtime error: load of misaligned address 0x2b8f9ce80e85 for type 'const qlonglong', which requires 8 byte alignment src/corelib/tools/qhash.cpp:133:26: runtime error: load of misaligned address 0x2b8f9ce80e8d for type 'const ushort', which requires 2 byte alignment Fix by memcpy()ing into a local variable. Wrap this trick in template functions in qsimd_p.h. These are marked as always- inline and use __builtin_memcpy() where available in an attempt to avoid the memcpy() function call overhead in debug builds. While this looks prohibitively expensive, from the pov of the C++ abstract machine, it is 100% equivalent, except for the absence of undefined behavior. In one case, the cast produces a local temporary which is then copied into the function, and in the other case, that local variable comes from return value of qUnalignedLoad(). Consequently, GCC compiles these two versions into identical assembler code (only verfied for ucstrncmp, but there's no reason to believe that it wouldn't hold for the other cases, too). Task-number: QTBUG-51651 Change-Id: Ia50d4a1d7580b6f803e0895c9f3d89c7da37840c Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
* | ARMv8: fix crc intrinsic usage.Erik Verbruggen2016-03-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | ARMv8 defines the crc32 instructions as optional features. Even though the target might be ARMv8, the compiler might have been told that the target CPU doesn't support it, in which case __ARM_FEATURE_CRC32 is not defined. Subsequently, the arm_acle.h header might only define the intrinsics when __ARM_FEATURE_CRC32 is defined. Change-Id: I85efcf9efdd2e152e3f3e72310122eebf543ca3b Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
* | Introduce QHash::equal_range()Sérgio Martins2016-02-141-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | Similar to QMap::equal_range(). Will allow to easily fix inefficient code such as: foreach (auto value, hash.values(key)) { ... } [ChangeLog][QtCore][QHash] Added QHash::equal_range() Change-Id: I6e19e25de632e897ad83d3141d9d07f0313f7200 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | Merge remote-tracking branch 'origin/5.6' into devLiang Qi2016-02-111-1/+1
|\| | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/io/qfilesystemwatcher_win.cpp src/corelib/plugin/plugin.pri src/plugins/platforms/cocoa/qcocoaaccessibility.mm tests/auto/corelib/tools/qlocale/tst_qlocale.cpp Change-Id: Id6824631252609a75eff8b68792e4d10095c8fc1
| * Doc: corrected minor link issuesNico Vertriest2016-02-051-1/+1
| | | | | | | | | | | | Task-number: QTBUG-43810 Change-Id: I98eafe0c7ed55f309640e8495c83ffcef355aa08 Reviewed-by: Martin Smith <martin.smith@theqtcompany.com>
| * Revert "Fix deadlock when setting environment variables."Oliver Wolff2015-11-241-15/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 5b62a5e7aabcc818408f2fe28b9760082f474def. This commit is reverted due to two reasons: 1) It was written incorrectly and does not work as is. The ifdefs should be ifndefs. In its current state, it does the exact opposite of what it is supposed to be doing. 2) There is another environment access inside qsimd.cpp (which checks QT_NO_CPU_FEATURE). This access causes the app to hang. All in all that approach is not sustainable as we might get bitten by environment access again and again. Instead we should use another environment container or use a recursive mutex for WinRT and Windows CE. Task-number: QTBUG-49529 Change-Id: Iaca76404dc1023551a7c25489a609681135765fd Reviewed-by: Andrew Knight <andrew.knight@intopalo.com> Reviewed-by: Samuel Nevala <samuel.nevala@intopalo.com>
| * Fix deadlock when setting environment variables.Samuel Nevala2015-11-231-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Qt uses QHash as the container for faking environment variables on Windows Runtime and CE. Environment variable manipulation functions are protected by mutex. Accessing the QT_HASH_SEED environment variable inside QHash can lead to situation where qputenv() call leads to qgetenv() call and that leads to a deadlock. Since the application environment is faked anyway, drop support for QT_HASH_SEED and ifdef that functionality out on those platforms. Documentation is updated to reflect changes. Task-number: QTBUG-49529 Change-Id: I1b1c28cb0b041fe2a63ca3dce57068fcb46505a7 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Andrew Knight <andrew.knight@intopalo.com>
* | Add Intel copyright to files that Intel has had non-trivial contributionThiago Macieira2016-01-211-0/+1
| | | | | | | | | | | | | | | | | | I wrote a script to help find the files, but I reviewed the contributions manually to be sure I wasn't claiming copyright for search & replace, adding Q_DECL_NOTHROW or adding "We mean it" headers. Change-Id: I7a9e11d7b64a4cc78e24ffff142b506368fc8842 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* | Updated license headersJani Heikkinen2016-01-151-14/+20
| | | | | | | | | | | | | | | | | | | | | | From Qt 5.7 -> LGPL v2.1 isn't an option anymore, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new LGPL header instead of LGPL21 one (in those files which will be under LGPL v3) Change-Id: I046ec3e47b1876cd7b4b0353a576b352e3a946d9 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* | ARMv8: Update qHash for strings to use the CRC32 instructionErik Verbruggen2016-01-131-0/+49
| | | | | | | | | | | | | | | | | | | | | | | | Same as the SSE4.2 implementation: use the (optional) ARMv8 crc32[bhwd] instruction to calculate hashes for strings. For Aarch64, support for the instruction is dynamically detected. For a 32bit ARM binary, dynamic detection is only done when the compiler is explicitly told to target ARMv8. When telling the compiler to target an other/older version, the crc32 code is not compiled. Change-Id: I51ebc1a4545dede4988247e75043f29a64c2a6c5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Add qHash(std::pair)Marc Mutz2015-12-301-0/+17
| | | | | | | | | | | | | | | | | | | | | | We already include <utility> in <qglobal.h>, so we might as well provide a qHash() overload for std::pair. [ChangeLog][QtCore] Added qHash(std::pair), defined in <QHashFunctions>. Change-Id: I0f61c513e82e05ce9d2e56bcf18f3be9e2da4da9 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* | QHash/QSet: add erase(const_iterator)Marc Mutz2015-12-191-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | This is the signature the functions have in C++11. For the std containers, this is just convenience, but for Qt containers with their implicit sharing problem, the combination of erase() with constFind() can delay a detach until absolutely necessary. [ChangeLog][QtCore][QHash/QSet] Added erase(const_iterator). Change-Id: I2fc841c664cd7515b0f56fd7210fcd17c37f9014 Reviewed-by: David Faure <david.faure@kdab.com>
* | Use Q_UNLIKELY for every qFatal()/qCritical()Marc Mutz2015-11-291-3/+3
|/ | | | | | | | | | | | | | | | | | | | | If, after checking a condition, we issue a qFatal() or a qCritical(), by definition that check is unlikely to be true. Tell the compiler so it can move the error handling code out of the normal code path to increase the effective icache size. Moved conditional code around where possible so that we could always use Q_UNLIKELY, instead of having to revert to Q_LIKELY here and there. In some cases, simplified the expressions newly wrapped in Q_UNLIKELY as a drive-by. Change-Id: I67537d62b04bc6977d69254690c5ebbdf98bfd6d Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* Add getter and setter for qt_qhash_seedGabriel de Dietrich2015-09-221-1/+49
| | | | | | | | | | | | | | | | | | In some cases it's not possible to use QT_HASH_SEED, specially when we need to set the environment variable from inside the application, as dynamically loaded libraries or plugins may create static QHash instances. That would set qt_qhash_seed to a value different from -1 and skip the env var value. For those cases, and when we still want to set qt_qhash_seed, we provide a way to enforce its value. Auto-tests accessing qt_qhash_seed directly have been updated accordingly. Usage in qdoc, uic and rcc has been left as is for the time being. Change-Id: I3b35b4fa0223c83b1348a6508641905a2a63266f Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* doc: Add a few missing const keywords in \fn commandsMartin Smith2015-08-161-2/+2
| | | | | | | | | This adds "const" to a few \fn commands for new operators in QHash and QMap. Change-Id: I93cf7aaf88fcb4db17de5810b555b978e8119e20 Task-number: QTBUG-47669 Reviewed-by: Topi Reiniö <topi.reinio@digia.com>
* Introduce QHash key iteratorsSérgio Martins2015-07-281-1/+147
| | | | | | | | | | | So we can have interoperability with algorithms. Motivated by inefficient code like qDeleteAll(hash.keys()) [ChangeLog][QtCore][QHash] Added key iterators, accessible through keyBegin() and keyEnd(). Change-Id: I1f9db8a7a4294e1556cbb50b8fe5ebdcf0dc29a2 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* QtCore: assorted migrations to QString::asprintfMarc Mutz2015-02-121-3/+2
| | | | | Change-Id: Ie99d3eeeced89dd8336717954fd5ca7117bb20b4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update copyright headersJani Heikkinen2015-02-111-7/+7
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* QHash: only fetch qt_qhash_seed when detaching from a null QHashMarc Mutz2015-01-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | The old code fetched QHashData::seed from qt_qhash_seed on every detach. That is both unnecessary and wrong. It is uneccessary, because if the detached-from QHashData isn't shared_null, the seed has already been populated from qt_qhash_seed. It thus suffices to fetch the seed from qt_qhash_seed only when we detach from shared_null. It is wrong, because if qt_qhash_seed was changed between the detach from shared_null and a following detach, d->seed is now different from this->seed, but detach_helper simply clones the buckets 1:1 from this to d, leaving d in a corrupt state. By doing this change, we make QHash robust against on-the-fly changes to qt_qhash_seed (e.g. for testing, or added security). It also opens up the option to have API for changing the seed of a given QHash instance after it has been created (detach, set new seed, rehash). Change-Id: Ib251fc9a6204b42036e97a2fc66f644b379ab841 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QHash: clean up class definitionMarc Mutz2015-01-101-10/+10
| | | | | | | ...by removing redundant '<Key, T>' and 'inline'. Change-Id: I9d81950c6384927633de07de511712f7274a1283 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Docs: e.g. -> for example in qhash.cppMarc Mutz2015-01-091-2/+2
| | | | | Change-Id: Ifee0117ddadfaa774fdd575467b03ca5b0baf433 Reviewed-by: Martin Smith <martin.smith@digia.com>
* Add qHashRange and qHashRangeCommutativeMarc Mutz2015-01-091-0/+85
| | | | | | | | | | | | | | | | | | | qHashRange() takes an (input iterator) range and hashes each element, combining the hash values using the hash combiner from Boost/N1837 with the magic number 0x9e3779b9, as described here: http://stackoverflow.com/questions/4948780/magic-number-in-boosthash-combine qHashRangeCommutative() does the same but with a cummutative combiner (unsigned addition) to create hash values that are order-independent, e.g. for hashed containers. The obvious combiner, XOR, is a bad one because it eliminates duplicate elements. Signed addition cannot be used, since signed overflow leads to undefined behavior. [ChangeLog][QtCore] Added qHashRange() and qHashRangeCommutative() functions to aid implementing qHash() overloads for custom types. Change-Id: I3c2bbc9ce4bd0455262a70e0cf248486525e534f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove Q_NO_USING_KEYWORDThiago Macieira2014-12-201-42/+0
| | | | | | | | | | | | | | | | | | | There's a lot of code now requiring it. Any compiler that doesn't support the keyword is too old for Qt now. The last time anyone asked about this macro was for QTBUG-27393 and we don't know which compiler that was. As a necessity, this patch contains a reversal of a0c3a57aed5cde37017733e7cf5e41cc6a1174aa [ChangeLog][Compiler Specific Changes] Qt 5.5 now unconditionally uses the "using" keyword. Compilers that do not support this keyword are deprecated and will not be able to build Qt. Previous versions of Qt may or may not compile, as no testing was done to ensure it worked. Change-Id: Ief042f34aba555a095d1f342a0ee7ee9feadf42d Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
* Merge remote-tracking branch 'origin/5.4' into devOswald Buddenhagen2014-09-291-19/+11
|\ | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/tools/qbytearray.cpp src/gui/image/qimage.cpp src/gui/image/qppmhandler.cpp src/gui/kernel/qguiapplication.cpp src/gui/painting/qpaintengine_raster.cpp Change-Id: I7c1a8e7ebdfd7f7ae767fdb932823498a7660765
| * Update license headers and add new license filesMatti Paaso2014-09-241-19/+11
| | | | | | | | | | | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* | QHash: remove unnecessary #ifdefMarc Mutz2014-09-121-3/+1
|/ | | | | | | | | | There's no need to use a macro here, since we can just store the pointer value in a qulonglong and have the second shift operation be done unconditionally. For 32-bit platforms, it will yield 0, and xor'ing it into 'seed' will have no effect. Change-Id: I3e63bd504e81c84d13935d5503c3707d40d74d6f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Document that qHash(T) must be in T's namespace, due to ADLThiago Macieira2014-07-231-4/+4
| | | | | | | | | | | | Due to C++'s rule of Argument-Dependent Lookup, a call to an unqualified qHash(t) will look up qHash in T's namespace. So edit the docs saying that it must be "global qHash" to say that it should be in the type's namespace. Task-number: QTBUG-34912 Change-Id: I7a72800008ccb710b4bb814e42db7a95f385f53e Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* Add support for single-file multi-target intrinsics in QtThiago Macieira2014-05-271-2/+3
| | | | | | | | | | | | | | | | | | | | | | | GCC 4.9 now allows us to #include any and all intrinsics headers, not just the one for which we're compiling code, a behavior that ICC and MSVC have had for some time. With that, we're able to have the functions for different targets in the same source file. See the GCC manual: http://gcc.gnu.org/onlinedocs/gcc/Function-Multiversioning.html This functionality is notified by the QT_COMPILER_SUPPORTS_HERE(XXX) macro, which indicates that all the intrinsics from QT_COMPILER_SUPPORTS_xxx are available and enabled. To complement, a QT_COMPILER_SUPPORTS(XXX) macro is also added. Unlike ICC and MSVC, GCC requires a special function attribute, which will also cause code optimization. That's the QT_FUNCTION_TARGET macro. Note: because of the absence of the target attribute, ICC and MSVC will not generate instructions with the VEX prefix unless they only exist with the VEX prefix or if -mavx / -arch:AVX are enabled. Change-Id: I0c1880c20324bd8e0fc68a863e36d1fa7755dff0 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
* Merge remote-tracking branch 'origin/stable' into devSimon Hausmann2014-05-221-5/+5
|\ | | | | | | Change-Id: Ia36e93771066d8abcf8123dbe2362c5c9d9260fc
| * Disable hash seeding for bootstrapped toolsThiago Macieira2014-05-211-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Any bootstrapped tool is a development tool, by definition. So the effects of seeding the hash with a random number can cause the same source input to produce different binary results, which can throw some caching tools into disarray (like the Open Build System). There should be minimal fall out from the reduced protection against DoS. Since those are only development tools, "specially crafted" input implies the developer is DoS'ing him/herself. Note: the change to qhash.cpp applies to moc and rcc, which are always bootstrapped. Change-Id: I061ab52036e40627c0703f1bf881455cbf848f43 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: hjk <hjk121@nokiamail.com>
| * Fix an off-by-4 error in qHash with CRC32Thiago Macieira2014-05-131-1/+1
| | | | | | | | | | | | | | | | | | I tested only the 64-bit build. The 32-bit build was reading garbage past the end of the strings in some cases. Change-Id: If6d239754e16a17cc4e8bb71e2b7778429dfa7ba Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* | Make qHash(QChar) constexprGiuseppe D'Angelo2014-03-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | The signature needs a small change -- from qHash(QChar, uint) to qHash(const QChar, uint). The reason is that we need to select the const (and constexpr) overload of QChar::unicode in the body. Apart from this, it shouldn't have any effect on user code. Change-Id: I38f4f66a715111c7472e3d7def75a6cff7030919 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | Add qHashBits(), a hash function for a memory blockMarc Mutz2014-02-281-0/+24
|/ | | | | | | | | | | The function arguments have been chosen to avoid caller-side casting of argument types, when passing object addresses and type sizeof()s. [ChangeLog][QtCore] Added qHashBits() to aid implementing qHash() overloads for custom types. Change-Id: I983a8560769bb27e489f23ebb6db51850ddd65f2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QHash: use prime numbers when rebucketingGiuseppe D'Angelo2014-02-191-8/+17
| | | | | | | | | | | | | | | | | | | | | QHash uses an array representing the difference between 2^i and the next prime; when growing, it calculates 2^x + array[x] (with `x' representing the "hash table size in bits"). For some reason lost in history the differences are actually wrong and the calculation above leads to using composite numbers. Hence: use the right sequence and always produce primes. The right sequence is actually A092131 from OEIS: http://oeis.org/A092131 Note that the sequence starts at A(1), but we need A(0) too. Also we truncate the sequence to when growing too much, just like the old code did, and use powers of two in that case instead. Task-number: QTBUG-36866 Change-Id: Id2e3fc9cb567c0fdca305dee38f480e17639ca04 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* Add qHash() overloads for floating-point typesMarc Mutz2014-02-161-0/+32
| | | | | | | | | | | | | | | | | | | | | This implementation is based on GCC's implementation of std::hash<FP>, but only to the extent of checking for zero before hashing the bits. The bit hasher is the Qt one; I didn't even look what GCC uses. The check against 0.0 is mandated by the requirement to have \forall x,y: x == y => qHash(x) == qHash(y) which would be violated for x = 0.0 and y = -0.0 if we only hashed the bits. Implemented out-of-line to avoid potential FP-comparison warnings, as well as to be able to use the file-static hash() functions, which gets inlined unlike qHashBits(), which cannot be. [ChangeLog][QtCore][QHash/QSet] Allowed to use float, double and long double as QHash/QSet keys. Change-Id: I38cec4afb860f17e9f8be7b67544e58b330f8fff Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* Update the qHash function for strings to use the CRC32 instructionThiago Macieira2014-01-231-0/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to my profiling of Qt Creator, qHash and the SHA-1 calculation are the hottest spots remaining in QtCore. The current qHash function is not really vectorizable. We could come up with a different algorithm that is more SIMD-friendly, but since we have the CRC32 instruction that can read 32- and 64-bit entities, we're set. This commit also updates the benchmark for QHash and benchmarks both the hashing function itself and the QHash class. The updated benchmarks for the CRC32 on my machine shows that the hashing function is *always* improved, but the hashing isn't always. In particular, the current algorithm is better for the "numbers" case, for which the data sample differs in very few bits. The new code is 33% slower for that particular case. On average, the improvement (including the "numbers" case) is: compared to qHash only QHash Qt 5.0 function 2.54x 1.06x Qt 4.x function 4.34x 1.34x Java function 2.71x 1.11x Test machine: Sandybridge Core i7-2620M @ 2.66 GHz with turbo disabled for the benchmarks Change-Id: Ia80b98c0e20d785816f7a7f6ddf40b4b302c7297 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Improve implicit shared documentation a bitThorbjørn Martsum2013-10-151-0/+10
| | | | | | | | Task-number: QTBUG-27061 Change-Id: I66e000a9f59fda3654066013e6e78c3ba6fd27fe Reviewed-by: Mitch Curtis <mitch.curtis@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Adding mark-up to boolean default values.Jerome Pasion2013-10-081-19/+19
| | | | | | | | | | | | | | | | | Default values should have mark-up to denote that they are code. This commit changes: -"property is true" to "property is \c true". -"Returns true" to "Returns \c true". -"property is false" to "property is \c false". -"returns true" to "returns \c true". -"returns false" to "returns \c false". src/3rdparty and non-documentation instances were ignored. Task-number: QTBUG-33360 Change-Id: Ie87eaa57af947caa1230602b61c5c46292a4cf4e Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
* Doc: Add docs for rvalue references and move constructorsGeir Vattekar2013-09-271-0/+17
| | | | | | | | | These members were introduced in 4.8, but left undocumented. Because we consider undocumented API to be internal, the members are \since 5.2. Change-Id: I52e2840a8cfaa7f59f410b3e2a06c0942ea06539 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com> Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
* Correct QHash::values() documentation.Mitch Curtis2013-07-291-1/+1
| | | | | Change-Id: Ia19bd0578591f77e5aee1c7e3e619ba97754f384 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
* Add qt_hash(QStringRef) overloadGiuseppe D'Angelo2013-05-071-4/+21
| | | | | | | | This enables fixing a performance regression compared to Qt 4. Also, add some qt_hash tests. Change-Id: Id830e17dec99fb67e5930c80029ac2233b2f427e Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
* Whitespace cleanup: remove trailing whitespaceAxel Waggershauser2013-03-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Remove all trailing whitespace from the following list of files: *.cpp *.h *.conf *.qdoc *.pro *.pri *.mm *.rc *.pl *.qps *.xpm *.txt *README excluding 3rdparty, test-data and auto generated code. Note A): the only non 3rdparty c++-files that still have trailing whitespace after this change are: * src/corelib/codecs/cp949codetbl_p.h * src/corelib/codecs/qjpunicode.cpp * src/corelib/codecs/qbig5codec.cpp * src/corelib/xml/qxmlstream_p.h * src/tools/qdoc/qmlparser/qqmljsgrammar.cpp * src/tools/uic/ui4.cpp * tests/auto/other/qtokenautomaton/tokenizers/* * tests/benchmarks/corelib/tools/qstring/data.cpp * util/lexgen/tokenizer.cpp Note B): in about 30 files some overlapping 'leading tab' and 'TAB character in non-leading whitespace' issues have been fixed to make the sanity bot happy. Plus some general ws-fixes here and there as asked for during review. Change-Id: Ia713113c34d82442d6ce4d93d8b1cf545075d11d Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
* Added initializer list constructors for Qt associative containers.Roman Pasechnik2013-01-241-0/+20
| | | | | | | | | Affected: QSet, QMap, QMultiMap, QHash, QMultiHash. Task-number: QTBUG-25679 Change-Id: I01f3ecfbca805f4c053a75232188bd2a77fdb1f2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* Update copyright year in Digia's license headersSergio Ahumada2013-01-181-1/+1
| | | | | Change-Id: Ic804938fc352291d011800d21e549c10acac66fb Reviewed-by: Lars Knoll <lars.knoll@digia.com>