From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pierre Habouzit Subject: Re: [PATCH] Optimize prefixcmp() Date: Sun, 30 Dec 2007 14:55:57 +0100 Message-ID: <20071230135557.GA25917@artemis.madism.org> References: Mime-Version: 1.0 Content-Type: multipart/signed; boundary="SLDf9lqlvOQaIe6s"; protocol="application/pgp-signature"; micalg=SHA1 Cc: Johannes Schindelin , Git Mailing List To: Marco Costalba X-From: git-owner@vger.kernel.org Sun Dec 30 14:57:01 2007 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1J8yeu-0003YG-1c for gcvg-git-2@gmane.org; Sun, 30 Dec 2007 14:56:56 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752431AbXL3N4B (ORCPT ); Sun, 30 Dec 2007 08:56:01 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753429AbXL3N4B (ORCPT ); Sun, 30 Dec 2007 08:56:01 -0500 Received: from pan.madism.org ([88.191.52.104]:44027 "EHLO hermes.madism.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752289AbXL3N4A (ORCPT ); Sun, 30 Dec 2007 08:56:00 -0500 Received: from madism.org (unknown [82.236.23.208]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "artemis.madism.org", Issuer "madism.org" (not verified)) by hermes.madism.org (Postfix) with ESMTP id BA6BF2C1E8; Sun, 30 Dec 2007 14:55:58 +0100 (CET) Received: by madism.org (Postfix, from userid 1000) id A81584ADE56; Sun, 30 Dec 2007 14:55:57 +0100 (CET) Mail-Followup-To: Pierre Habouzit , Marco Costalba , Johannes Schindelin , Git Mailing List Content-Disposition: inline In-Reply-To: X-Face: $(^e[V4D-[`f2EmMGz@fgWK!e.B~2g.{08lKPU(nc1J~z\4B>*JEVq:E]7G-\6$Ycr4<;Z!|VY6Grt]+RsS$IMV)f>2)M="tY:ZPcU;&%it2D81X^kNya0=L]"vZmLP+UmKhgq+u*\.dJ8G!N&=EvlD User-Agent: Madmutt/devel (Linux) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: --SLDf9lqlvOQaIe6s Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Dec 30, 2007 at 01:02:28PM +0000, Marco Costalba wrote: > Subject: [PATCH] Certain codepaths (notably "git log --pretty=3Dformat...= ") use >=20 > prefixcmp() extensively, with very short prefixes. In those cases, > calling strlen() is a wasteful operation, so avoid it. >=20 > Initial patch by Johannes Schindelin. >=20 > Signed-off-by: Marco Costalba > --- > git-compat-util.h | 11 ++++++++++- > 1 files changed, 10 insertions(+), 1 deletions(-) >=20 > diff --git a/git-compat-util.h b/git-compat-util.h > index 79eb10e..843a8f5 100644 > --- a/git-compat-util.h > +++ b/git-compat-util.h > @@ -398,7 +398,16 @@ static inline int sane_case(int x, int high) >=20 > static inline int prefixcmp(const char *str, const char *prefix) > { > - return strncmp(str, prefix, strlen(prefix)); > + do { > + if (*str !=3D *prefix) > + return *(unsigned const char *)prefix - *(unsigned const char *)str; > + > + if (!*(++prefix)) > + return 0; > + > + str++; > + > + } while (1); This code doesn't work if prefix is "". You want something like: for (; *prefix; prefix++, str++) { if (*str !=3D *prefix) return *(unsigned const char *)prefix - *(unsigned const char *= )str; } return 0; --=20 =C2=B7O=C2=B7 Pierre Habouzit =C2=B7=C2=B7O madcoder@debia= n.org OOO http://www.madism.org --SLDf9lqlvOQaIe6s Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQBHd6NtvGr7W6HudhwRAvmkAKCF4ABdIFxWep8Nn2fFKZOpr9+ZmQCdFMIY lxgFGe57Y48LpT6Kn4JjfEY= =dN2m -----END PGP SIGNATURE----- --SLDf9lqlvOQaIe6s--