PATCH/RFC Pool allocations of QStringData objects..

Roger Larsson kde-optimize@mail.kde.org
Sat, 18 Jan 2003 13:33:22 +0100


On Saturday 18 January 2003 11:31, David Faure wrote:
> On Saturday 18 January 2003 06:20, Maks Orlovich wrote:
> > The vast majority of the used memory seems to be the history, which I=20
guess is
> > OK, considering that it's information we actually do need. However, the
> > protocols reappear an awful lot -- logging the strings getting freed=20
(yeah,
> > that misses non-freed ones, I know), I can do:
> >
> > cat ../log|grep http$ |wc -l
> >    3127
> >
> > cat ../log|grep file$ |wc -l
> >     805
> >
> > cat ../log|grep https$ |wc -l
> >     167
> >
> >
> > i.e. nearly 4000 strings are just copies of "http", "https" and "file"
> > protocol names. I wonder whether there is a way to get rid of that
> > efficiently.. (Some sort of a global protocol name dictionary?)
>=20
> Using more of KGlobal::staticQString() would get rid of the "checking for=
 a=20
particular protocol" ones.

Not really... IMHO

>=20
> But since KURL stores urls as separate QStrings, a lot of the protocols y=
ou=20
see above
> are actually part of the history KURLs.
>=20

Does this patch help? I do not think so...

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=2D-- kurl.cpp    13 Jan 2003 15:47:40 -0000      1.229
+++ kurl.cpp    18 Jan 2003 12:20:55 -0000
@@ -37,7 +37,7 @@

 #include <qtextcodec.h>

=2Dstatic const QString fileProt =3D "file";
+static const QString &fileProt =3D KGlobal::staticQString("file");

 static QTextCodec * codecForHint( int encoding_hint /* not 0 ! */ )
 {
@@ -573,7 +573,7 @@ void KURL::parse( const QString& _url, i

   if ( pos+2 < len && buf[pos] =3D=3D ':' && buf[pos+1] =3D=3D '/' && buf[=
pos+2] =3D=3D=20
'/' )
     {
=2D      m_strProtocol =3D QString( orig, pos ).lower();
+       m_strProtocol =3D QString( orig, pos ).lower(); // Two QStrings cre=
ated?
       pos +=3D 3;
     }
   else if (pos+1 < len && buf[pos] =3D=3D ':' ) // Need to always compare=
=20
length()-1 otherwise KURL passes "http:" as legal!!
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

The second part is why I do not think it wont help.
It creates a sub string from a original string (that has been created=20
somewhere too...) and then creates another one as a result of lower()
The QStrings themselves is not the problem (they can be allocated on the st=
ack
since they are temporary) but the contents data.

What we would like to do is something like this:

  KGlobal::OptOptions opt;
  opt.setSubString(from=3D1, to=3Dpos);
  opt.setConvertion(KGlobal::OptOptions::lowerCase);

  m_strProtoCol =3D KGlobal::OptimizedQString(orig, optimizationOptions);

If there is no static registered with this string it could return a fresh=20
copy.

Any takers?

/RogerL

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