[ki18n] src: small qstring optimizations
David Faure
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
good idea.
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:
=========
http://bugs.kde.org/show_bug.cgi?id=93675
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
font.fromString("Sans Serif,9,-1,5,50,0,0,0,0,0");
-> 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
with pointSize=6.5
See http://www.davidfaure.fr/kde/qfont_early_app_font_bug.cpp
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
are doing)
(http://code.google.com/p/thread-sanitizer/wiki/PopularDataRaces)
=========
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
mailing list