Proposal KLatin1String

Simon Hausmann hausmann at kde.org
Mon Mar 29 18:11:04 CEST 2004


On Monday 29 March 2004 12:14, Dr. Juergen Pfennig wrote:
> > I think everyone here would be curious to see the implementation of this
> > class. Do you have some code to share already?
>
> Yes, but in a very early stage. I must confess that I did not look at the
> code for KLatinString(Literal) before. Now I did - and I am not sure that
> the current implementation will speed-up things or reduce the code size
> significantly. The problem with such classes it that they must provide a
> significant improvement or must provide some nice functionality. Otherwise
> there is no reason to use them and they would only add complexity to KDE.

Well, the significant improvement is that there no more is the conversion from 
latin1 to ucs2 just for the single comparison, which included at least two 
mallocs and a bit of data copying.

> A technical concern about KLatinString(Literal) is that data() returns a
> pointer to memory that is not managed by the KLatinSring(Literal) class.
> The assumption is that the data passed to the xtor is static and remains
> valid for the lifetime of a KLatinString(Literal). This is a dangerous
> thing and may lead to instable code when programmers forget to respect
> these restrictions.

I'm afraid there is little that can be done against it. If you start copying 
the string then you loose the advantage of the class.

KLatin1String/Literal is not really meant for general purpose. I think it's 
meant to be used in library code, by people who know what they are doing. The 
documentation could stress this. Everywhere else it probably doesn't really 
matter.

Simon


More information about the Kde-optimize mailing list