[PATCH] let QString::lower() assume lower case input to avoid real_detach()
Roger Larsson
kde-optimize@mail.kde.org
Sun, 19 Jan 2003 03:00:33 +0100
--Boundary-00=_BbgK+opc/6aopsC
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
As it said in the earlier comments "could do this only when we find a chang=
e"
This version does it like that.
upper could be optimized in the same way, but there it is questionable
if the all upper case in common enough...
It compiles but I have not tested it yet - Monday earliest.
My assumption is that this will speed up history loading.
/RogerL
=2D-=20
Roger Larsson
Skellefte=E5
Sweden
--Boundary-00=_BbgK+opc/6aopsC
Content-Type: text/x-diff;
charset="iso-8859-1";
name="qstring.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="qstring.patch"
Index: qstring.cpp
===================================================================
RCS file: /home/kde/qt-copy/src/tools/qstring.cpp,v
retrieving revision 1.51
diff -u -3 -p -r1.51 qstring.cpp
--- qstring.cpp 17 Dec 2002 15:04:18 -0000 1.51
+++ qstring.cpp 19 Jan 2003 01:39:26 -0000
@@ -15004,13 +15004,36 @@ QString QString::lower() const
QString s(*this);
int l=length();
if ( l ) {
- s.real_detach(); // could do this only when we find a change
- register QChar *p=s.d->unicode;
+ QChar *p=s.d->unicode;
if ( p ) {
- while ( l-- ) {
- *p = ::lower( *p );
+ // check if all are lower already
+ while ( l )
+ {
+ QChar c_anycase = *p;
+ QChar c_lower = ::lower( c_anycase );
+
+ if (c_anycase != c_lower) { // !__builtin_expect
+ s.real_detach(); // only when we found a change
+
+ // p might have moved due to the detach, recalculate it
+ // then update the mismatching char
+ p=s.d->unicode + length() - l; // might have moved, note the remaining l(ength)
+ *p = c_lower;
+
+ while ( --l ) {
+ *p = ::lower( *p );
+ p++;
+ }
+
+ break;
+ }
+
+ // more logical to do it in the same place
+ // and probably optimized better (decrement before test)
p++;
+ l--;
}
+
}
}
return s;
--Boundary-00=_BbgK+opc/6aopsC--