[Development] QDateTime is missing shared null optimization
Milian Wolff
milian.wolff at kdab.com
Fri Jul 31 17:20:02 CEST 2015
Hello all,
I just realized that QDateTime in Qt 5 is still not implementing the "shared null optimization" - I'm not sure
it's the right term.
What I mean is that you'll incur a heap allocation when doing
QDateTime invalidDate;
See:
QDateTime::QDateTime()
: d(new QDateTimePrivate)
{
}
Most other classes in Qt are cheap to generate in an empty/invalid state, not so for QDateTime. Is there a
reason for that, or is it just an oversight? If so, I'd like to amend that. Would it be preferred to introduce a
shared null like QTypedArrayData::sharedNull, or should I rather use a nullptr to indicate the invalid state,
like in QImage? Or am I missing something and these tricks are not applicable to QDateTime?
Grepping for QSharedDataPointer, I find many more classes that do not leverage a shared null state. Should
we try to implement some helper functions/macros there which can be leveraged by every user of this
class to implement a shared null state?
Bye
--
Milian Wolff | milian.wolff at kdab.com | Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt Experts
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20150731/9a19303e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5903 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20150731/9a19303e/attachment.bin>
More information about the Development
mailing list