All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Whitcroft <apw@shadowen.org>
To: hanwen@xs4all.nl
Cc: git@vger.kernel.org
Subject: Re: weird strncmp usage?
Date: Thu, 02 Nov 2006 01:44:36 +0000	[thread overview]
Message-ID: <45494D84.2060402@shadowen.org> (raw)
In-Reply-To: <eibhga$tpg$1@sea.gmane.org>

Han-Wen Nienhuys wrote:
> 
> Hi,
> 
> the git source seems full of calls similar to
> 
>   strncmp (x, "constant string", 15)
> 
> is there a reason not to use something like
> 
>   int
>   strxmp (char const *x, char const *y)
>   {
>     return strncmp (x, y, strlen (y));
>   }
> 
> everywhere?

If you are doing these a _lot_ then there is a significant additional
cost to using strlen on a constant string.

That said if you know its constant you can also use sizeof("foo") and
that is done at compile time.  Something like:

#define strxcmp(x, y)	strncmp((x), (y), sizeof((y))

-apw

  reply	other threads:[~2006-11-02  1:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-02  1:26 weird strncmp usage? Han-Wen Nienhuys
2006-11-02  1:44 ` Andy Whitcroft [this message]
2006-11-02  6:51   ` Jeff King
2006-11-02  9:15     ` Johannes Schindelin
2006-11-02  9:59       ` Han-Wen Nienhuys
2006-11-02 11:04   ` Petr Baudis
2006-11-03 21:05   ` Florian Weimer

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=45494D84.2060402@shadowen.org \
    --to=apw@shadowen.org \
    --cc=git@vger.kernel.org \
    --cc=hanwen@xs4all.nl \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.