From: Alex Riesen Date: Sun, 07 Oct 2007 21:57:49 GMT Subject: Re: [PATCH] Make strbuf_cmp inline, constify its arguments and optimize it a bit Message-ID: <20071007215749.GD2765@steel.home> In-Reply-To: <851wc6lwkc.fsf@lola.goethe.zz> David Kastrup, Sun, Oct 07, 2007 18:27:15 +0200: > Alex Riesen writes: > >> > +static inline int strbuf_cmp(const struct strbuf *a, const struct strbuf *b) > >> > +{ > >> > + int len = a->len < b->len ? a->len: b->len; > >> > + int cmp = memcmp(a->buf, b->buf, len); > >> > + if (cmp) > >> > + return cmp; > >> > + return a->len < b->len ? -1: a->len != b->len; > >> > +} > >> > >> My guess is that you are conflating two issues about speed here: the > >> inlining will like speed the stuff up. But having to evaluate the > >> (a->len < b->len) comparison twice will likely slow it down. > > > > Can't the result of the expression be reused in compiled? > > Isn't it a common expression? > > No, since the call to memcmp might change a->len or b->len. A Huh?! How's that? It is not even given them!