implicit QChar constructors

Waldo Bastian kde-optimize@mail.kde.org
Tue, 21 Jan 2003 21:55:05 +0100


On Tuesday 21 January 2003 21:15, Jesse Yurkovich wrote:
> The second piece of code was, of course, much much faster than the first
> because of all the constructor calls going on (even for small values of N).
> The second loop just used the same value over and over. Code such as the
> above is nearly everywhere in KDE's sources and the most likely culprites
> for implicit QChar being created are of the form: '\t',  '\n',  ' ',  '\r',
>  etc.

I don't think code like this is used too much throughout KDE. A quick grep 
shows mostly constructs of the form:
	int     p = model.find(' ',0);
and
	if (opt_name[0] == ' ')

Since recently Qt overloads most functions that take QChar with one that takes 
char as well, so in none of these cases an actual QChar needs to be 
constructed.

*check* *cough*

If it wasn't for the actual implementation in Qt :-]

inline int QString::find( char c, int index, bool cs ) const
{ return find(QChar(c), index, cs); }

But the other one looks good :)

inline bool operator==( QChar c, char ch )
{
    return ((uchar) ch) == c.ucs;
}

Cheers,
Waldo
-- 
bastian@kde.org -=|[ SuSE, The Linux Desktop Experts ]|=- bastian@suse.com