[alt PATCH] Re: [PATCH] KURL optimizations
Roger Larsson
kde-optimize@mail.kde.org
Fri, 10 Jan 2003 23:14:30 +0100
--Boundary-00=_GX0H+FgZBqJkWjt
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
On Friday 10 January 2003 05:34, Maks Orlovich wrote:
> > Why is its argument (and result) const anyway?
> > All uses creates the QString before call.
> > I am not sure that this part is worth it...
> > Instead try to avoid all uses of QChar pointers.
>=20
> Hmm?? QChar pointers are essentially pointers to ushorts. The only worris=
ome=20
> part here is that QChar::lower() can't be inlined.=20
>=20
You did several changes how much of the speed improvement was due to the
(IMHO ugly hack) QString_lower?
I have made an alternative patch with some other optimizations.
(I am compiling currently... It compiles - lets ship it :-)
/RogerL
=2D-=20
Roger Larsson
Skellefte=E5
Sweden
--Boundary-00=_GX0H+FgZBqJkWjt
Content-Type: text/x-diff;
charset="iso-8859-1";
name="new-kurl.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="new-kurl.patch"
--- kurl.cpp.orig 2003-01-10 23:06:36.000000000 +0100
+++ kurl.cpp 2003-01-10 23:05:15.000000000 +0100
@@ -182,10 +182,14 @@
if (!textCodec)
textCodec = QTextCodec::codecForLocale();
- if (!textCodec->canEncode(segment))
- textCodec = codecForHint( 106 ); // Fall back to utf-8 if it doesn't fit.
-
QCString csegment = textCodec->fromUnicode(segment);
+ // Check if everything went ok
+ if (textCodec->toUnicode(csegment) != segment)
+ {
+ // Uh oh
+ textCodec = codecForHint( 106 ); // Fall back to utf-8
+ csegment = textCodec->fromUnicode(segment);
+ }
old_length = csegment.length();
int new_length = 0;
@@ -529,6 +533,13 @@
return (m_strPath.isEmpty() && m_strProtocol.isEmpty());
}
+//#ifdef KDE_QT_ONLY
+ const QString fileProt = "file";
+//#else
+// I am afraid that this is not a optimization... I try it this way...
+// static const QString & fileProt = KGlobal::staticQString( "file" );
+//#endif
+
void KURL::parse( const QString& _url, int encoding_hint )
{
//kdDebug(126) << "parse " << _url << endl;
@@ -544,9 +555,8 @@
bool badHostName = false;
int start = 0;
uint len = _url.length();
- QChar* buf = new QChar[ len + 1 ];
- QChar* orig = buf;
- memcpy( buf, _url.unicode(), len * sizeof( QChar ) );
+ const QChar* buf = _url.unicode();
+ const QChar* orig = buf;
QChar delim;
QString tmp;
@@ -786,14 +796,14 @@
NodeOk:
//kdDebug(126)<<"parsing finished. m_strProtocol="<<m_strProtocol<<" m_strHost="<<m_strHost<<" m_strPath="<<m_strPath<<endl;
- delete []orig;
m_bIsMalformed = false; // Valid URL
- if (m_strProtocol.isEmpty())
- m_strProtocol = "file";
//kdDebug()<<"Prot="<<m_strProtocol<<"\nUser="<<m_strUser<<"\nPass="<<m_strPass<<"\nHost="<<m_strHost<<"\nPath="<<m_strPath<<"\nQuery="<<m_strQuery_encoded<<"\nRef="<<m_strRef_encoded<<"\nPort="<<m_iPort<<endl;
- if (m_strProtocol == "file")
+ if (m_strProtocol.isEmpty() || (m_strProtocol == fileProt))
{
+ // Assign even if it was equal to fileProt - why?
+ // Now it is the same object too! Later tests will compare fast (comparing with a 'char *' will always check each character)
+ m_strProtocol = fileProt;
if (!m_strHost.isEmpty())
{
// File-protocol has a host name..... hmm?
@@ -814,7 +824,6 @@
NodeErr:
// kdDebug(126) << "KURL couldn't parse URL \"" << _url << "\"" << endl;
- delete []orig;
reset();
m_strProtocol = _url;
}
@@ -1071,11 +1080,6 @@
void KURL::setEncodedPath( const QString& _txt, int encoding_hint )
{
-#ifdef KDE_QT_ONLY
- QString fileProt = "file";
-#else
- static const QString & fileProt = KGlobal::staticQString( "file" );
-#endif
m_strPath_encoded = _txt;
decode( m_strPath_encoded, m_strPath, m_strPath_encoded, encoding_hint );
@@ -1107,11 +1111,6 @@
bool KURL::isLocalFile() const
{
-#ifdef KDE_QT_ONLY
- QString fileProt = "file";
-#else
- static const QString & fileProt = KGlobal::staticQString( "file" );
-#endif
return ( ( m_strProtocol == fileProt ) && ( m_strHost.isEmpty()) && !hasSubURL() );
}
@@ -1511,7 +1510,7 @@
}
// Users home directory on the local disk ?
- if ( ( _dir[0] == '~' ) && ( m_strProtocol == "file" ))
+ if ( ( _dir[0] == '~' ) && ( m_strProtocol == fileProt ))
{
m_strPath_encoded = QString::null;
m_strPath = QDir::homeDirPath();
@@ -1656,7 +1655,9 @@
if (isEmpty())
m_bIsMalformed = false;
if (m_strProtocol.isEmpty())
- m_strProtocol = "file";
+ {
+ m_strProtocol = fileProt;
+ }
m_strPath = path;
m_strPath_encoded = QString::null;
}
--Boundary-00=_GX0H+FgZBqJkWjt--