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 | [email protected] | Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt Experts

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to