summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qdatetime.cpp
Commit message (Collapse)AuthorAgeFilesLines
* QDateTimePrivate: replace out parameters with return-by-value in getDateTime()Marc Mutz2015-03-251-34/+33
| | | | | | | | | | | | Compilers don't like out parameters. Effects on Linux GCC 4.9 stripped release builds: text -584B data +-0B relocs +-0 Change-Id: Ie00c89b9edaced3a6adeb2707734c8f5238e67c1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime: prevent aggressive inliningMarc Mutz2015-03-251-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The function getDateFromJulianDay() is simple arithmetic, but still ~400 bytes in executable size. Yet GCC inlines this everywhere I looked, which makes some sense, as different users of the class only use parts of the return value and the optimizer has a field day removing all that dead code. However, that function has only one conditional, so presumably it executes at full pipeline speed and it doesn't matter that it calculates too much in some cases. More important is to use the I-cache more conservatively. That's what not inlining the function achieves. The function returns its result in registers and doesn't spill registers when called (at least on AMD64), so the effect on runtime should be negligible. Effects on Linux GCC 4.9 stripped release builds: text -1536B data +-0B relocs +-0 Change-Id: Ia16838102d29ad67ee5efdc8b7b0a26f2f921df1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTime: optimize toString()Marc Mutz2015-03-251-3/+1
| | | | | | | | | | | | | Instead of using a QString::arg() cascade, which creates tons of temporaries, use good 'ol sprintf(). Effects on Linux GCC 4.9 stripped release builds: text -308B data +-0B relocs +-0 Change-Id: I348577491d1399b5040f7ed9e9f6b111a9528e5d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Micro-optimize QDate::{long,short}{Day,Month}Name()Marc Mutz2015-03-251-32/+28
| | | | | | | | | Save one return statement per function. I don't see why the compiler can't fuse these itself, but apparently it cannot, since this transformation saves 72B in text size. Change-Id: I3a661456554bf451ed53110ad546946ff7b84ec5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDate: don't spend code size covering the impossible caseMarc Mutz2015-03-251-1/+1
| | | | | | | | | | | | All other similar functions in QDate just return an empty string in case none of the switch labels would trigger (which would now cause a compiler warning, after removing the default case label), so do that here, too. Saves 44B in text size. Change-Id: I80ee4975082706adcd15fe89511d08c67e149324 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDate: remove some useless default case labelsMarc Mutz2015-03-251-8/+0
| | | | | | | | | | | | They're pure whitespace, since in each case there is a fallback after the switch, anyway, and their presence prevents compiler warnings about unhandled enumeration values in switch statements, which is nice-to-have, when adding to the enum, eventually. No change in executable code size. Change-Id: I77aecaeff990601f957ec9ee827eff5ead25aaa1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime: ensure we always use the daylight status if knownThiago Macieira2015-03-111-19/+28
| | | | | | | | | Refactor the code so that the localMSecsToEpochMSecs function always gets the daylight status as input. The calculation can be very wrong if we forget to set it. Change-Id: I39e2a3fa6dc7c4a417f23288f10b303e450b8b98 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
* Fix regression in time zone handlingFrederik Gladhorn2015-03-111-0/+1
| | | | | | | | | | | | In QtScript we use the msecs since epoch conversion (JS date is based on the concept). After a8c74ddcf78604c9038ba2a2bea81e445e4b3c58 the date conversion test in qtscript started to fail. Instead of relying on the code working by chance, simply update the date when setting it with setMSecsSinceEpoch. Task-number: QTBUG-44885 Change-Id: I9f95c9cdccea52e7d1f808f3cb9e18570ef0df13 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Simplify calculation of week numberLars Knoll2015-03-101-50/+17
| | | | | | | This also removes a dependency to 3rd party licensed code. Change-Id: Ia4818a5cf306501bdb7192265edc4bcba8e597d8 Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
* Fix race condition in QDateTime::timeZone() and other methodsThiago Macieira2015-03-071-25/+30
| | | | | | | | | | | | | | | | | | | | When timezone support for QDateTime was added, we decided it was a good idea to delay creating the QTimeZone object and checking that the time is valid in that timezone (including for local time) until the user requested that information. Unfortunately, QExplicitlySharedDataPointer returns a non-const T* in operator->(), which meant we were accidentally modifying the d pointer's contents in const methods, which in turn means those const methods were not thread-safe when operating on the same object. This commit changes the d pointer to QSharedDataPointer, which is safer in this regard and pointed out where the issues with constness were located. Since we can't lazily calculate QTimeZone anymore, we need to do it whenever the date, time or offset changes. Task-number: QTBUG-43703 Change-Id: Ic5d393bfd36e48a193fcffff13b9686ef4ef1454 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* QDateTime: cache the result of date.timeSpec() in QDebug op<<Marc Mutz2015-02-211-2/+3
| | | | | | | Saves a couple dozen bytes in text size on optimized AMD64 builds. Change-Id: Iefd9ca05a7b27f240836c1e1e00df569742fcd7f Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QDateTime: drop quotes in QDebug outputMarc Mutz2015-02-211-1/+2
| | | | | | | | | As requested in review of 1d2efe1f27bedcbaa157ef4e82b8eda33dda46ad. I didn't add a comma in front of the timeSpec() as the other fields aren't separated by commas, either. Change-Id: I54d74b7199ca7e46e28d2ceca22b02205e318c90 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QDate: optimize QDate::toString()Marc Mutz2015-02-171-3/+1
| | | | | | | | | | | | | Instead of using a QString::arg() cascade, which creates tons of temporaries, use good 'ol sprintf(). Effects on Linux GCC 4.9 stripped release builds: text -216B data +-0B relocs +-0 Change-Id: I6ff551cb9f42e0c05a64f03a8e177fb527915481 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime: optimize toOffsetString()Marc Mutz2015-02-171-10/+6
| | | | | | | | | | | | | | | Instead of using a QString::arg() cascade, which creates tons of temporaries, use good 'ol sprintf(). As a consequence, this function is now inlined into all four callers and the total executable size _still_ goes down: Effects on Linux GCC 4.9 stripped release builds: text -420B data +-0B relocs +-0 Change-Id: I10d6abd94b489db7c2f01dc5424f30a798602522 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime: replace out parameters with return-by-value in rfcDateImpl()Marc Mutz2015-02-171-66/+32
| | | | | | | | | | | | Compilers *really* don't like out parameters. (Impressive) effects on Linux GCC 4.9 stripped release builds: text -2512B data +-0B relocs +-0 Change-Id: I0fe370a438f7b82aaa9cc04ddd56e45a5969e7a9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime: optimize rfcDateImpl()Marc Mutz2015-02-171-20/+22
| | | | | | | | | | | | | Get the captured texts once and use indexing into the QStringList instead of repeatedly calling QRegExp::cap(n). (Impressive) effects on Linux GCC 4.9 stripped release builds: text -2876B data +-0B relocs +-0 Change-Id: I3a02eab1a691f31c30654cd89a0c030414b40de0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime: change an instance of out parameters to return-by-valueMarc Mutz2015-02-171-52/+48
| | | | | | | | | | | | Compilers don't like out parameters. Effects on Linux GCC 4.9 stripped release builds: text -528B data +-0B relocs +-0 Change-Id: I32ee1a6c4388900bacfc6eb20feb4b81d71cb1f2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime: micro-optimize QDebug op<<Marc Mutz2015-02-151-8/+5
| | | | | | | | | | | | | | | | Instead of constructing a QString that describes the QDateTime instance, stream the constituents of the string into QDebug directly, using op<< for Q_ENUM, now that it's available. Adapt test to new format of enums. Effects on Linux GCC 4.9 stripped release builds: text -1068B data +-0B relocs +-0 Change-Id: I1a5ce28904edd7d0f6c8d982fd41c52e3536e036 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Updated BSD licensed file headersJani Heikkinen2015-02-151-1/+1
| | | | | Change-Id: I6441ff931dbd33b698d762e6f6784898f3f60fe7 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* QDateTime: make qt_monthNumberFromShortName() staticMarc Mutz2015-02-141-1/+1
| | | | | | | | | | | | It wasn't Q_DECL_EXPORT'ed, and there is no other user in QtCore. Effects on Linux GCC 4.9 stripped release builds: text -344B data +-0B relocs +-0 Change-Id: Iea0577d58057a145f87a00ec33995d03bacd4f88 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QDateTime: use existing functions for short month name parsingMarc Mutz2015-02-141-35/+21
| | | | | | | | | | | | ...instead of rolling a new one on each use. Effects on Linux GCC 4.9 stripped release builds: text -156B data +-0B relocs +-0 Change-Id: I49e20ea859928d010990fc7a22545dbc1ef106ec Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QDateTimePrivate: enable read caching on m_status in setDateTime()Marc Mutz2015-02-141-6/+6
| | | | | | | | | | | | | | | Help the compiler by building the new status flags in a local instead of a member variable. Enables value tracking for that piece of data across several non-inline function calls, leading to less redundant reads through this->. Effects on Linux GCC 4.9 stripped release builds: text -248B data +-0B relocs +-0 Change-Id: I2db21439464ad0fff8163a908de3b15df7c4ab6d Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
* QDateTime: pass explicit length to QLatin1String ctorMarc Mutz2015-02-141-1/+1
| | | | | | | | | | | | | Apparently, determining that constant at compile time is a bit too much work for GCC. Effects on Linux GCC 4.9 stripped release builds: text -276B data +-0B relocs +-0 Change-Id: I23144e64d57e3a2e1061e69b20f2b72575c273d8 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* QDateTime: avoid relocationsMarc Mutz2015-02-141-1/+1
| | | | | | | | | | | | | The short month names all have length 3, so store them in a multi- dimensional const char array instead of as a pointer table. Effects on Linux GCC 4.9 stripped release builds: text -196B data -64B relocs -12 (est., somehow relinfo.pl reports nonsense on QtCore) Change-Id: If5f83e4f1eb5ba0b0f54b4144abec8b88fb8529f Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
* Update copyright headersJani Heikkinen2015-02-111-8/+8
| | | | | | | | | | | | | | | | | | 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>
* QtCore: Use QDebugStateSaver in (almost) all QDebug operator<<Kai Koehne2015-02-091-3/+6
| | | | | | | | | Unify the behavior of the different operator<< by always using QDebugStateSaver (appending an optional space at exit), and making sure that the space(), nospace() setting isn't 'leaked'. Change-Id: I38e4f82fa6f7419d8b5edfc4dc37495af497e8ac Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
* Merge remote-tracking branch 'origin/5.4' into devFrederik Gladhorn2015-01-211-18/+24
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/global/global.pri src/corelib/global/qcompilerdetection.h src/corelib/global/qglobal.h src/corelib/tools/qdatetime.cpp src/plugins/platforms/xcb/qxcbscreen.h src/plugins/platforms/xcb/qxcbwindow.h src/widgets/dialogs/qcolordialog.cpp src/widgets/dialogs/qcolordialog_p.h tools/configure/configureapp.cpp Change-Id: Ie9d6e9df13e570da0a90a67745a0d05f46c532af
| * Update doc saying QDateTime::setTime with invalid time sets to midnightThiago Macieira2015-01-151-3/+10
| | | | | | | | | | | | | | | | | | QDateTimePrivate::setDateTime has a comment saying this is intentional, so document it. Task-number: QTBUG-43704 Change-Id: Ic5d393bfd36e48a193fcffff13b965409eaf7be9 Reviewed-by: Martin Smith <martin.smith@digia.com>
| * Doc: Fixed date format doc bug in QDateTime/Qt namespaceOrgad Shaneh2015-01-061-12/+12
| | | | | | | | | | | | | | | | | | | | MM stands for month, SS is invalid mostly cherry picked from Qt4 commit 670f460fab6a386407c07281cf6417ccf6430970. Task-number: QTBUG-12236 Change-Id: I7af4be655d2d10f1befa1366abb48225c60d31dc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
| * [QDateTime] ISO Time zone designators can be [+-]HHIsrael Lins2014-12-301-5/+4
| | | | | | | | | | | | | | | | | | Added support on QDateTime::fromString to read correctly dates on ISO format with Time zone designators at format [+-]HH Change-Id: Ied5c3b7950aee3d0879af0e05398081395c18df5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Mark Brand <mabrand@mabrand.nl>
* | Don't call static members with objectThiago Macieira2015-01-161-3/+3
| | | | | | | | | | | | | | This makes it clear that we're not modifying d. Change-Id: Ic5d393bfd36e48a193fcffff13b968c6d08e69f6 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* | Add QTimeZone::{systemTimeZone,utc}Thiago Macieira2015-01-161-5/+3
| | | | | | | | | | | | | | | | | | [ChangeLog][QtCore][QTimeZone] Added methods systemTimeZone() and utc() that return QTimeZone objects for the system time zone and for UTC, respectively. Change-Id: Ic5d393bfd36e48a193fcffff13b96821bb8514b9 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
* | Merge remote-tracking branch 'origin/5.4' into devFrederik Gladhorn2014-10-201-1/+1
|\| | | | | | | Change-Id: If7e51514ed6832750e3ad967e4d322ccf920d2bb
| * Make QStringRef::right() consistent with QString::right()Eskil Abrahamsen Blomfeldt2014-10-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The implementation was inconsistent with QString::right(), and did not return the N rightmost characters but actually did the same as QString::mid(N) (returning the rightmost size - N characters.) Since this function is fairly recent (Qt 5.2), is documented to behave the same as QString::right(), and since these APIs are meant to be interchangeable, this needs to be fixed, even though it changes behavior. [ChangeLog][Important Behavior Changes] Changed QStringRef::right() to be consistent with QString::right(). The function now returns the N right-most characters, like the documentation already claimed. Change-Id: I2d1cd6d958dfa9354aa09f16bd27b1ed209c2d11 Task-number: QTBUG-41858 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
* | Merge remote-tracking branch 'origin/5.4' into devFrederik Gladhorn2014-10-091-2/+2
|\| | | | | | | Change-Id: I05fcd8dc66d9ad0dc76bb7f5bae05c9876bfba14
| * Don't use QStringLiteral in comparisonsMarc Mutz2014-10-091-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | For QLatin1String, operator== is overloaded, so comparing to a latin-1 (C) string literal is efficient, since strlen() is comparatively fast. OTOH, QStringLiteral, when not using RVO, litters the code with QString dtor calls, which are not inline. Worse, absent lambdas, it even allocates memory. So, just compare using QLatin1String instead. Change-Id: I7af3bf3a67c55dae33ffaf9922d004fa168a3f9c Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Add Objective-C specific type converters to QDateTimeJake Petroules2014-10-071-0/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds the Objective-C NSDate/CDateRef converters to QDateTime [ChangeLog][QtCore][Objective-C] Added NSDate/CDateRef converters for QDateTime Task-number: QTBUG-37116 Change-Id: I937ea927083a2767b5b17f10a48bf453c9ff8b01 Reviewed-by: Jake Petroules <jake.petroules@petroules.com> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@digia.com>
* | Merge remote-tracking branch 'origin/5.4' into devOswald Buddenhagen2014-09-291-25/+18
|\| | | | | | | | | | | | | | | | | | | | | 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>
| * Doc: corrected autolink errors qtbase/corelib/toolsNico Vertriest2014-09-241-6/+7
| | | | | | | | | | | | | | | | | | Also corrected some minor language/spelling issues Task-number: QTBUG-40362 Change-Id: I00d76521fc9beb4e7a4a83ff6dc3334a055a7148 Reviewed-by: Topi Reiniö <topi.reinio@digia.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
* | QDateTime: Micro-optimize by using QString::fromLatin1 instead of ↵Robin Burchell2014-09-151-16/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | QString::fromUtf8. This data is clearly not (and will never be) utf8 data, so using fromLatin1 avoids the (slightly more expensive) utf8 mangling. I didn't see any significant impact on benchmarks, but I also wasn't specifically collecting data when making this change. Change-Id: I45190d40b2caccf15b1f9a1ae5b7dcd08cbd541f Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | QDate: Micro-optimize for fromStringIso benchmark.Robin Burchell2014-09-151-2/+2
| | | | | | | | | | | | | | | | By using QStringRef instead of QString, we avoid a data copy. This takes the QDateTime::fromStringIso benchmark from 0.79ms to 0.53ms for me. Change-Id: Ibb36067491ffc275ce3b667cb0e04941aa9457f0 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | Optimize qdatetime string parsingJędrzej Nowacki2014-08-141-16/+16
|/ | | | | | | | Replacing usage QString::split by QString::splitRef saves a few allocations. Change-Id: I1cadca296279248b75af6f9f8394c54f13c37c55 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
* Reduce QtCoreLib size by not repeating "UTC" string too often.Jędrzej Nowacki2014-07-251-3/+3
| | | | | | | | It is a minor reduction, in release build it is ~200 bytes Change-Id: I4f7972c95769f2e0ca1ddc935ff7a0a6b4379e2a Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
* Speedup qDebug() << QDate(...)Jędrzej Nowacki2014-07-141-1/+1
| | | | | | | We really do not need to do string parsing there. Change-Id: Ie2277d9ff0d0445285b7108023941af111d9baca Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Call tzset() before localtime_r() as the docs say.Gunnar Sletta2014-05-161-0/+3
| | | | | | | | Without it, one might run the risk of QDateTime::currentDateTime() returning an invalid QDateTime the first time after changing timezone. Change-Id: I3efb04d41e7fe4685f6cc5fb41b68424eb4b9eb8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime: Fix sign handling in the timezone offset writerDaniel Seither2014-05-081-1/+1
| | | | | | | | | Previously, this produced wrong results, for example -3:30 became -3:-30. Change-Id: I10efdfb48e5542b917c86b29cf8a99bfc26f7fe0 Reviewed-by: John Layt <jlayt@kde.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QDateTime: Fix sign handling in the timezone offset parserDaniel Seither2014-05-081-6/+13
| | | | | | | | | | | | | Previously, parsing negative timezone offsets with minutes != 00 produced wrong results. Examples (in -> out) -00:15 -> +00:15 -01:15 -> -00:45 Change-Id: I6fa30810a08bdf2996365661720b2e362e8aeb93 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: John Layt <jlayt@kde.org>
* Correctly manipulate tm_gmtoff the way qt_timezone() needs.Raphael Kubo da Costa2014-02-071-1/+11
| | | | | | | | | | | | | Follow-up to 91d3298: qt_timezone() expects the number of seconds west of UTC, whereas tm_gmtoff returns the number of seconds east of UTC, and contrary to the timezone variable it is not oblivious to DST. We have to account for those two facts and make sure we return a value compatible with what timezone would have. Change-Id: Iacb9077f50d4c847ac09e5a7e952d0e4cd22da1b Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge "Merge remote-tracking branch 'origin/stable' into dev" into ↵Frederik Gladhorn2014-01-211-11/+45
|\ | | | | | | refs/staging/dev