[ki18n] src: small qstring optimizations
faure at kde.org
Sun Jan 25 11:36:08 UTC 2015
On Wednesday 21 January 2015 21:32:07 Nick Shaforostoff wrote:
> +static const QString SUBSTITUTE_ME=QStringLiteral("%1");
I'm not sure that adding global static (non-POD) objects in libraries is a
We've had many problems with that in the past (see below for details), and
they slow down application startup by having to create all these global
objects even if they are never going to be used.
Here are my notes about why global static objects are bad:
Another example (Qt4) :
messagelist/core/messageitem.cpp had a file-global QFont.
This initialized the application font to DPI 75 (no QApp yet).
Later on, this meant a very weird bug:
QFont font; // == initialized to the app font
-> the font request becomes pointSize=9 pixelSize=9 (BUG!) due to dpi=75
-> later on qfontdatabase_x11.cpp uses DPI 96 (from appDpiY) and ends up
And: If a program calls exit() while other threads are still running, static
objects may be destructed by one thread and used by another thread at the same
time. Conclusion: don't use static non-POD objects unless you know what you
PS: nowadays most commits to KDE Frameworks go via reviewboard so they can be
reviewed prior to being pushed.
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5
More information about the Kde-frameworks-devel