linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Egger <degger@fhm.edu>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: torvalds@transmeta.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] streq()
Date: 25 Sep 2002 13:27:32 +0200	[thread overview]
Message-ID: <1032953252.18004.18.camel@sonja.de.interearth.com> (raw)
In-Reply-To: <20020924045313.0FBE52C075@lists.samba.org>

[-- Attachment #1: Type: text/plain, Size: 1324 bytes --]

Am Die, 2002-09-24 um 06.49 schrieb Rusty Russell:

> Embarrassing, huh?  But I just found a bug in my code cause by
> "if (strcmp(a,b))" instead of "if (!strcmp(a,b))".

> diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal linux-2.5.38/include/linux/string.h working-2.5.38-streq/include/linux/string.h
> --- linux-2.5.38/include/linux/string.h	2002-06-06 21:38:40.000000000 +1000
> +++ working-2.5.38-streq/include/linux/string.h	2002-09-24 14:43:30.000000000 +1000
> @@ -15,7 +15,7 @@ extern "C" {
>  extern char * strpbrk(const char *,const char *);
>  extern char * strsep(char **,const char *);
>  extern __kernel_size_t strspn(const char *,const char *);
> -
> +#define streq(a,b) (strcmp((a),(b)) == 0)

Considering most compares will only care for equality/non-equality and
not about the type of unequality a strcmp usually returns, wouldn't it
be more wise and faster to use an approach like memcpy for comparison
instead of that stupid compare each character approach?

Something along the lines of:
Start comparying by granules with the biggest type the architecture has
to offer which will fit into the length of the string and going down
to the size of 1 char bailing out as soon as the granules don't match.
 
-- 
Servus,
       Daniel

[-- Attachment #2: Dies ist ein digital signierter Nachrichtenteil --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  parent reply	other threads:[~2002-09-25 11:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-24  4:49 [PATCH] streq() Rusty Russell
2002-09-24  5:40 ` Ingo Molnar
2002-09-24  6:04   ` Rusty Russell
2002-09-24  6:24     ` David S. Miller
2002-09-24  7:28       ` Rusty Russell
2002-09-24  7:38         ` Ingo Molnar
2002-09-24  8:19         ` David S. Miller
2002-09-24 13:07   ` Denis Vlasenko
2002-09-24 17:21   ` H. Peter Anvin
2002-09-25 11:27 ` Daniel Egger [this message]
2002-09-25 11:45   ` Russell King
2002-09-25 12:38     ` Daniel Egger
2002-09-25 12:19   ` Michael Sinz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1032953252.18004.18.camel@sonja.de.interearth.com \
    --to=degger@fhm.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).