KGlobal::staticQString current recomendation harmful?

Roger Larsson kde-optimize@mail.kde.org
Mon, 13 Jan 2003 08:16:29 +0100


On Sunday 12 January 2003 12:01, Simon Hausmann wrote:
> On Sun, Jan 12, 2003 at 04:48:25AM +0100, Roger Larsson wrote:
> > Hi,
> >=20
> > From the documentation.
> >=20
> >     /**
> >      * Creates a static QString.
> >      *
> >      * To be used inside functions(!) like:
> >      * <pre>
> >      * static const QString &myString =3D KGlobal::staticQString("myTex=
t");
> >      * </pre>
> >      *
> > 	[CONTINUED later]
> >=20
> > "Use inside of functionS"
> > 	OK, so what if I have 100 functions that uses the same string?
> > 	then the function staticQString need to run 100 times at startup.
> > 	later when running it is no problem but... startup time is an issue to=
o!
> > 	[Current CVS with my run have 251 misses and 171 hits=20
> > 	 - pretty bad hit rate that is, patch included]
>=20
> I think the main idea behind staticQString is less to share as much
> data as possible (nice side effect) but more to get around the
> problem that some platforms we support have problems with static
> objects in functions (them not calling the constructor or destructor
> under certain circumstances) . I can't imagine it to be really
> relevant to startup time of applications.

But the point is: there is NO need to use those static objects in functions=
=20
anyway.
1) Use a static const object in the file, if all/most uses are local
2) Use a static const object in the class, if all/most uses are in a small=
=20
group of files
3) Use the staticQString at file level, if all/most uses are anywere else.
4) If there are someplace where dynamic strings are checked against a
   group of strings then an extention to staticQString could be use to speed
   it up! (get a index of a string together with the const object)
But DO NOT use staticQString in all functions/methods that need it since
it will cause numerous executions of the code before even entering main()
=2D and that is were we really are slow...

/RogerL

=2D-=20
Roger Larsson
Skellefte=E5
Sweden