[tested PATCH] let QString::lower() assume lower case input to avoid real_detach()

Roger Larsson kde-optimize@mail.kde.org
Fri, 24 Jan 2003 21:02:25 +0100


On Friday 24 January 2003 19:42, Harri Porten wrote:
> On Fri, 24 Jan 2003, Harri Porten wrote:
>=20
> > >  If it's tested patch, you could probably send it to=20
qt-bugs@trolltech.com :).
> >=20
> > No need to. I will fix* and improve it a bit and check it into qt-copy =
for
> > everyone to tes^H^H^Henjoy :)
>=20
> I found an elegant solution done by a colleague to be present in the main
> (e.g. HEAD) branch already. Just applied my change that removes the imo
> redundant if(p) check:
>=20
> QString QString::lower() const
> {
>     int l =3D length();
>     if ( l ) {
> 	register QChar *p =3D d->unicode;
> 	while ( l ) {
> 	    if ( *p !=3D ::lower(*p) ) {
> 		QString s( *this );
> 		s.real_detach();
> 		p =3D s.d->unicode + ( p - d->unicode );
> 		while ( l ) {
> 		    *p =3D ::lower( *p );
> 		    l--;
> 		    p++;
> 		}
> 		return s;
> 	    }
> 	    l--;
> 	    p++;
> 	}
>     }
>     return *this;
> }
>=20

My code looked much like this before I cleaned it up :-)

This code nests deeper,=20
has an return in the middle,
does one more ::lower - twice on the first char that differs

The extra check agains 'l' in my code should be optimized away
by any decent compiler since it is the last check done in the
do {...} while () loop...

Summary: IMHO my code is better :-)

[BTW isn't the setDirty needed - will a copy automatically be
marked as dirty (i.e. ascii is not copied) - yea I guess that
I can check the source...]

/RogerL


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