Re: [PATCH] Make strbuf_cmp inline, constify its arguments and optimize it a bit
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Oct 7, 2007, 16:11 UTC
- Message-ID
- <Pine.LNX.4.64.0710071710190.4174@racer.site>
- In-Reply-To
- <20071007143912.GB10024@artemis.corp>
Hi,
On Sun, 7 Oct 2007, Pierre Habouzit wrote:
Show 12 quoted lines
> On Sun, Oct 07, 2007 at 02:24:25PM +0000, Timo Hirvonen wrote:
>
> > strbuf->buf is always non-NULL and NUL-terminated so you could just do
> >
> > static inline int strbuf_cmp(const struct strbuf *a, const struct strbuf *b)
> > {
> > int len = a->len < b->len ? a->len : b->len;
> > return memcmp(a->buf, b->buf, len + 1);
> > }
>
> doesn't work, because a buffer can have (in some very specific cases)
> an embeded NUL.But it should work. The function memcmp() could not care less if there is a NUL or not, it just compares until it finds a difference.
Ciao, Dscho