summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qtranslator.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QTranslator: enable NRVO in find_translation() for poor compilersMarc Mutz2016-01-121-1/+2
| | | | | | | | | | | | | | | ... such as GCC. truncate(0) was chosen because it is already used throughout the function. Using clear(), say, which is inline, produces slightly more code. As is, saves 160b in text size on optimized GCC 4.9 Linux AMD64 builds. Change-Id: I415d09ad2b4547f1d69f78d85e2aa1c1f9a17ed3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* QTranslator: optimize string handling in find_transformationMarc Mutz2016-01-121-1/+2
| | | | | | | | | | - Don't repeatedly truncate a (shared) QString, truncate a QStringRef instead, preventing a detach. Change-Id: I1a9cf7fc5bc9ea06279f7e2548f2bd144b8780a3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* QtCore: eradicate all Q_FOREACH loops [kernel]Marc Mutz2016-01-121-3/+3
| | | | | | | | Saves just 168b in text size on optimized GCC 4.9 Linux AMD64 builds, but most for loops are in non-Linux code. Change-Id: I4f20a65c2e4953011308ff831c9e8fa37a25274b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTranslator: don't repeatedly re-create a QString from a QLatin1StringMarc Mutz2016-01-111-2/+3
| | | | | | | | | | | | | ... each time around the loops. Cache it. Also use QStringLiteral, since the string will never be modified. Also saves 96b in text size on optimized GCC 4.9 Linux AMD64 builds. Change-Id: I0269586235da18f3073a553739561ea7db6356e8 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QTranslator: re-use 'realname' capacity in find_translation()Marc Mutz2016-01-111-7/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | For almost the whole of its life time, 'realname' has the same prefix, but the old code used the same string-builder expression to construct it over and over again. If QStringBuilder would re-use the capacity of the LHS object, that would boil down to just a bit more copying of characters than necessary. But assigning a QStringBuilder expression to a QString works by implicit conversion of the QStringBuilder expression to a QString, followed by move-assigning the new QString into the old. The new code keeps the common prefix around, resetting 'realname' to that prefix with truncate, only appending the varying suffixes. In this way, one memory allocation per assignment is saved (ignoring a potentially required capacity increase in one of the appends here), and also some out-of-line QString dtor calls, since op+=(QString&, QStringBuilder...) doesn't create a temporary QString. Also saves ~1KiB in text size on optimized GCC 4.9 Linux AMD64 builds. Change-Id: I0872a69c9111d7218567f06f8fefb010f2430532 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTranslator: Extract Method is_readable_file from find_translation()Marc Mutz2016-01-041-15/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The old code re-used a QFileInfo object, repeatedly setting new file names with QFileInfo::setFile(QString). But QFileInfo::setFile() simply assigns itself a new QFileInfo object: *this = QFileInfo(...) so it's just as efficient to re-create a new QFIleInfo object for every file name under test. To avoid extra {} for object lifetime scoping, factor the repeated evaluation of isReadable() && isFile() into a small helper function, which also creates and destroys the QFileInfo object. The deeper significance of this change is that it avoids implicit sharing of 'realname', which is permanently modified. A later patch will make changes that make 'realname' re-use its capacity through the lifetime of the find_translation() function, and sharing the variable implicitly will nip any auch attempts in the bud. Force the compiler to not inline the new function. There's really no point in spending ~0.5KiB in text size on inlining the code; the miniscule speed improvement is dwarfed by the memory allocation of the QFileInfo ctor, anyway. As a consequence, this change even saves 96b in text size on optimized GCC 4.9 Linux AMD64 builds, even though that wasn't even the goal. Change-Id: I08c5cbb7b6f1ba59440a1597e28d962ce63a7c65 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.5' into devFrederik Gladhorn2015-08-061-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: doc/global/qt-cpp-defines.qdocconf src/3rdparty/forkfd/forkfd.c src/corelib/codecs/qtextcodec.cpp src/corelib/kernel/qmetatype.cpp src/corelib/tools/qset.qdoc src/gui/accessible/qaccessible.cpp src/gui/image/qpixmapcache.cpp src/opengl/qgl.cpp src/tools/qdoc/generator.cpp src/widgets/kernel/qwidget.cpp tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp Change-Id: I4fbe1fa756a54c6843aa75f4ef70a1069ba7b085
| * Doc: Don't advertise QLocale::system() in QTranslator::load documentationKai Koehne2015-07-231-1/+1
| | | | | | | | | | | | | | | | | | | | Usually you want to use just QLocale(), and not QLocale::system(). They are both the same except when the user called QLocale::setDefault() beforehand. Change-Id: I2d9b13ac3ffec0005b1d9bf661eccdea276d34b1 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Martin Smith <martin.smith@digia.com>
* | Remove <qhash.h> where it's not usedMarc Mutz2015-04-201-1/+0
|/ | | | | | | | To avoid source-incompatibilites, wrap in QT_DEPRECATED_SINCE(5, 5) in public headers. Change-Id: I6117e8a6b11200d2f1a0a94a0e87d5c27538218e Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.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>
* Merge remote-tracking branch 'origin/5.4' into devSimon Hausmann2014-12-101-8/+12
|\ | | | | | | | | | | | | | | Conflicts: doc/global/template/style/online.css mkspecs/android-g++/qmake.conf Change-Id: Ib39ea7bd42f5ae12e82a3bc59a66787a16bdfc61
| * Fix warnings by MSVC 64 in qtranslator.cpp.Friedemann Kleint2014-12-051-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | kernel\qtranslator.cpp(880) : warning C4267: 'initializing' : conversion from 'size_t' to 'const uint', possible loss of data kernel\qtranslator.cpp(881) : warning C4267: 'initializing' : conversion from 'size_t' to 'const uint', possible loss of data kernel\qtranslator.cpp(882) : warning C4267: 'initializing' : conversion from 'size_t' to 'const uint', possible loss of data kernel\qtranslator.cpp(975) : warning C4267: 'initializing' : conversion from 'size_t' to 'const int', possible loss of data Task-number: QTBUG-39757 Change-Id: I54f130e1d83ecc1623ab3c7b9b4fb14de6351625 Reviewed-by: Albert Astals Cid <albert.astals@canonical.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
| * Don't make invalid assumptions about memcmp()Albert Astals Cid2014-12-041-8/+12
| | | | | | | | | | | | | | | | In qtranslator.cpp match() Task-number: QTBUG-39757 Change-Id: I49e3ccc0ce900564bbe14609bfda47688382d5f3 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* | Merge remote-tracking branch 'origin/5.4' into devFrederik Gladhorn2014-11-241-3/+2
|\| | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/io/qiodevice.cpp src/plugins/bearer/linux_common/qofonoservice_linux.cpp src/plugins/bearer/linux_common/qofonoservice_linux_p.h src/plugins/platforms/android/qandroidplatformtheme.cpp src/tools/bootstrap/bootstrap.pro src/widgets/styles/qmacstyle_mac.mm Change-Id: Ia02aab6c4598ce74e9c30bb4666d5e2ef000f99b
| * Fix incorrect documentation from QTranslator::loadAki Koskinen2014-11-051-3/+2
| | | | | | | | | | | | Task-number: QTBUG-27506 Change-Id: I1b2d4ed2242efd52258c7f587c2121f9dde18a0d Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* | Make the empty Q_ASSERT still check its argument for validityThiago Macieira2014-11-011-0/+1
|/ | | | | | | | | | | | | | | | | | | | | With the side-effect that variables and functions in the argument are now "used". This means we don't need to #ifndef functions only used in assertions: the compiler will eliminate them by dead code elimination. Due to the mandatory short-circuiting of the condition, no functions will ever be called and this expands to no more code than before. On the negative side, because we won't get warnings for unused variables initialized outside the Q_ASSERT, non-inlineable calls will not be elminated by dead code elimination, so they will remain in release code without warnings. Because of the expanded code now in Q_ASSERT, the Intel compiler's optimizer gets thrown: it complains that the non-void function is failing to return anything, so I had to add two return statements. Change-Id: I1bb79c9637a2771ef1ec093f901b8d2443788bd6 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* Doc: Fix description of QTranslator::translate()Kai Koehne2014-10-231-0/+5
| | | | | | | | | | | If the translations are incomplete it's actually not ensured that a translation without disambiguation is used: lrelease will drop the disambiguation from one of the identical messages if there is no message which actually has no disambiguation ... Task-number: QTBUG-30471 Change-Id: I1787f5c401a7afb964acbf8a8609ba328c8140a9 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* 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>
* Doc: recommend using QLocale for loading translationsLeena Miettinen2014-04-161-0/+6
| | | | | | | | | | | Users can choose to use different UI languages and regional settings on their devices. QTranslator::load(const QLocale &) function uses QLocale::uiLanguages() and not to the locale name, which refers to the formatting of dates and numbers. Change-Id: Iec6327dd1e91d913176499b23482d725b9d0a8aa Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
* Doc: Adding mark-up to boolean default values.Jerome Pasion2013-10-081-5/+5
| | | | | | | | | | | | | | | | | 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: QTranslator::translate() isn't an overload anymoreDavid Faure2013-06-191-2/+0
| | | | | | Change-Id: Ib50044da48be3fb4f43300aa285e15403bd8d65e Reviewed-by: Jerome Pasion <jerome.pasion@digia.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@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>
* QtBase: Doc: Replacing link with snippet in QTranslator.David Schulz2012-12-051-3/+3
| | | | | | | | Because the linguist examples are moved to qttools module, a link to the hellotr example broke. Change-Id: I2aeefc143578618396f5be38ed1d52afdd1f7436 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@digia.com>
* QTranslator: Use resource memory instead of copying itThomas McGuire2012-11-021-35/+66
| | | | | | | | | Previously, translations in resource files were loaded through QFile and the data was copied. Now, simply use the resource memory in-place. Change-Id: I55a06c1e7bb15c169cc69b908b3021136beac9d2 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
* Add parameter documentation.Frederik Gladhorn2012-10-161-1/+1
| | | | | Change-Id: I8ce85bbb286c3cb844ef600daa5e99432ee55b74 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-24/+24
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* Core: Fix gcc warning about signed/unsigned integer comparisonKai Koehne2012-09-181-1/+1
| | | | | | | Fix warning: 'comparison between signed and unsigned integer expressions' Change-Id: I5ce2857115137f9a06eddc74fda55ae49e37d345 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Add \inmodule QtCore to all QtCore class doc bodiesThiago Macieira2012-08-231-0/+1
| | | | | Change-Id: I19100755c97cc155c76a859e19940e9f9222d34e Reviewed-by: Casper van Donderen <casper.vandonderen@nokia.com>
* Misc documentation fixes triggered by qdoc errors/warningsShawn Rutledge2012-08-201-3/+3
| | | | | Change-Id: I6ca3b138114fe957a09e8ec2f22273865635fc8b Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
* Fix more qdoc errorsLars Knoll2012-08-201-6/+6
| | | | | Change-Id: Ieed340068327f37ea0f549d24ea49235994118f4 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix a couple of qdoc errorsLars Knoll2012-08-181-1/+0
| | | | | Change-Id: I79f689e08ed4a496052529af38fca72c3d4e04cb Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Enable modularization of translation files.Jan-Arve Saether2012-07-121-17/+60
| | | | | | | | | | | | | | | | | This is accomplished by introducing dependencies to catalogs. This requires one API change: QTranslator::load(const uchar *, int); changes to QTranslator::load(const uchar*, int len, const QString &directory = QString()); Since now, even the load from memory might need a directory if the memory block contains a qm file with dependencies. Change-Id: I781f333d07f53bb431d0a7b5fa1abe282dc4d338 Task-number: QTBUG-26138 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Doc: Prepare for building modular QtCore docs.Casper van Donderen2012-04-191-1/+1
| | | | | | | | | | | | This change fixes most qdoc errors in QtCore. There are about 900 left. The main thing this change does is moving documentation from qtcore from /doc/src to /src/corelib/doc. Other issues resolved are mis-use of qdoc commands. Change-Id: I002d01edfb13575e8bf27ce91596a577a92562d1 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com> Reviewed-by: Jerome Pasion <jerome.pasion@nokia.com>
* Make numerus unsignedJoão Abecasis2012-03-301-6/+5
| | | | | | | It's the index number of the translation to be used. Change-Id: I959c6aaa1aad09e74286d201ea356bfc4409f02a Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Pre-validate numerus rules: fail early, fail gracefullyJoão Abecasis2012-03-301-17/+80
| | | | | Change-Id: Ibb3d27b9ff3d2f356a7c5c98b98686342f001f8f Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Verify presence of "magic cookie" before more expensive readsJoão Abecasis2012-03-301-5/+15
| | | | | | | | | | Moved this simple sanitation out of do_load as it will prevent us from loading misplaced (or misfound) files into memory in the first place. We'll still load anything minimally looking like a translation file. Change-Id: Ia138be010979d4a66d330f7414fce3df20727e68 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Use unsigned variable for size and indexJoão Abecasis2012-03-301-2/+2
| | | | | | | | rulesSize is passed from unsigned variable numerusRulesLength, so don't bring sign bit into equation; array index variable i also made unsigned. Change-Id: I0cb4e8483272c1e60339298149fb118215aa2183 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Fix comments out of touch with realityJoão Abecasis2012-03-301-3/+3
| | | | | Change-Id: Id060626b0bb6c28f4e67c9b3c7a0fbc456f7dcc6 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Clean up and make robust the file loading codeJoão Abecasis2012-03-281-37/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The used_mmap variable was set to true the first time an mmap operation was successful, but it was never reset back to false. While that can be a good indicator that future calls might succeed it is not a guarantee. Not properly resetting could mean we'd unmap memory allocated with new, instead of deleting it. Since that variable is only used inside defined(QT_USE_MMAP) blocks, its declaration is scoped the same way. While mmap is still handled "by hand", use QFile for the other operations. Calling mmap here is less than ideal, as it prevents use of other memory mapping methods, such as native Windows APIs, but is less intrusive as it allows QTranslator to retain control over lifetime of the map. Using QFile for remaining operations reduces the number of filesystem operations. The file size is now checked to be minimally sane (<4GB), the limit of the 32-bit variable that will hold mapping's length. Translation files should be expected to be much smaller in practice, but there isn't a sane hard-limit. The file format is broken down to sections, each of which has a 32-bit length. Finally, when loading a file fails, release resources immediately, instead of delaying to next load attempt or the destructor. Change-Id: I5cc1b626a99d229e8861eb0fbafc42b928b6a122 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Fail when no translations found, reset pointers on failureJoão Abecasis2012-03-281-0/+14
| | | | | | | We don't want to be using or trusting partial loads. Change-Id: I3934d6cf54cd99eaab2fa7aee9a0e9968d9f3c13 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Use Big-Endian conversion functions from qendian.hJoão Abecasis2012-03-281-6/+4
| | | | | | | | These avoids repeating code and documents that the underlying format is compacted big-endian. Change-Id: I5a2dc0084945d99368183203a0a9b7c116874620 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Remove unused argumentJoão Abecasis2012-03-281-7/+1
| | | | | | | | | The mode argument (third argument to (_)open) is only used when (_)O_CREAT is also specified. As we're opening the file read-only it is unused and unnecessary. Change-Id: Icc16edec5a7d44c57ad02865048c56114c39d4bc Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* There's no need to check pre-validated inputJoão Abecasis2012-03-281-8/+6
| | | | | | | | elfHash and friends are used solely from do_translate, which already checks for null strings. There's no need to do it again here. Change-Id: I90a16d2623ca753a444e53952539001988568bdb Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Use accumulating hash, instead of allocating intermediate stringJoão Abecasis2012-03-281-4/+17
| | | | | Change-Id: Ie93ac8df3066159ad11ff7f68c7ba85e7f5aa8bc Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Avoid overflow in boundary checkJoão Abecasis2012-03-271-1/+1
| | | | | Change-Id: I4f397795a65d5d6ea237a6751588a8dc6be15bdc Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
* Remove the usage of deprecated qdoc macros.Casper van Donderen2012-03-021-28/+28
| | | | | | | | | | | QDoc now has support for Doxygen style commands for italics, bold and list items. This change applies that change in QDoc to the actual documentation. Task-number: QTBUG-24578 Change-Id: I519bf9c29b14092e3ab6067612f42bf749eeedf5 Reviewed-by: Shane Kearns <shane.kearns@accenture.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Remove Symbian specific code from QtCore.Xizhi Zhu2012-01-301-2/+2
| | | | | Change-Id: I131303e28a12dccb96de3de4ca0073b389a9bbae Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* Remove "All rights reserved" line from license headers.Jason McDonald2012-01-301-1/+1
| | | | | | | | | | As in the past, to avoid rewriting various autotests that contain line-number information, an extra blank line has been inserted at the end of the license text to ensure that this commit does not change the total number of lines in the license header. Change-Id: I311e001373776812699d6efc045b5f742890c689 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update contact information in license headers.Jason McDonald2012-01-231-1/+1
| | | | | | | Replace Nokia contact email address with Qt Project website. Change-Id: I431bbbf76d7c27d8b502f87947675c116994c415 Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
* Update copyright year in license headers.Jason McDonald2012-01-051-1/+1
| | | | | Change-Id: I02f2c620296fcd91d4967d58767ea33fc4e1e7dc Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>