[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: kdelibs/kfile
From: Matthias Welk <welk () fokus ! gmd ! de>
Date: 1999-06-24 15:43:20
[Download RAW message or body]
On Thu, 24 Jun 1999, Waldo Bastian wrote:
> Sirtaj Singh Kang wrote:
> >
> > On Wed, 23 Jun 1999, Hans Petter Bieker wrote:
> > [snip]
> > > I tried to create my own compare():
> > > bool compare( const QString &as, const QString &bs )
> > > {
> > > if (as.length() !=3D bs.length()) return false;
> > > const QChar *a = as.unicode();
> > > const QChar *b = bs.unicode();
> > > if (memcmp(a, b, as.length() * sizeof(QChar)) != 0)
> > > return false;
> > > return true;
> > > }
> > >
> > > That code seems to work, but uses only:
> > > real 0m0.681s
> > > user 0m1.562s
> > > sys 0m0.062s
> > >
> > > What am I missing?
> >
> > Hi,
> >
> > Well memcmp is not enough for a string comparison function is it?
> > strcmp returns
> > < 0 if string 1 is greater
> > > 0 if string 2 is greater
> > = 0 if strings are equal
> >
> > This means that the QChars will need to be tested if the strings
> > are not found to be equal after the first test.
>
> Perhaps we should have a
> "bool equal(const QString&, const QString &, int len=-1)"
> function which just does the above. Often you are not interested
> if a string comes alphabetically before or after the other.
>
The Trolls changed the == operator in their newest CVS-Snapshot to use
the memcmp approach :-) (according to the cvs log its 200% faster)
Greetings, Matthias.
--
---------------------------------------------------------------
From: Matthias Welk voice: +49-30-3463-7272
GMD Fokus fax : +49-30-3463-8272
Kaiserin-Augusta-Allee 31 email: welk@fokus.gmd.de
10589 Berlin
----------------------------------------------------------------
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic