From: Junio C Hamano Date: Tue, 20 Feb 2007 09:04:25 GMT Subject: Re: [PATCH] Change "refs/" references to symbolic constants Message-ID: <7vlkitxkrq.fsf@assigned-by-dhcp.cox.net> In-Reply-To: <200702200841.26578.andyparkins@gmail.com> Andy Parkins writes: > As I've said before, I'm against /any/ special treatment of > master other than as a default branch name in a newly > initialised repository. PATH_REFS_HEADS_MASTER is closer to > master not being special than without so I'd be in favour of > that. Ok. >> These repeated strncmp(p, X, STRLEN_X) almost makes me wonder if we >> want to introduce: >> >> inline int prefixcmp(a, b) >> { >> return (strncmp(a, b, strlen(b)); >> } >> >> with clever preprocessor optimization to have compiler do strlen() >> when b is a string literal. > > Wow; that would be clever - regardless of whether this patch > is acceptable or not. Actually GCC seems to be clever enough. It appears that I do not even have to do prefixcmp_0() below; prefixcmp_1() seems to generate good code, with GCC 4.1.2 prerelease on my x86_64. -- >8 -- #include static inline int prefixcmp_0(const char *a, const char *b) { if (__builtin_constant_p(b)) return strncmp(a, b, sizeof(b) - 1); else return strncmp(a, b, strlen(b)); } static inline prefixcmp_1(const char *a, const char *b) { return strncmp(a, b, strlen(b)); } void foo(const char *s, const char *t, int *a, int *b, int *c, int *d) { *a = prefixcmp_0(s, "abcdefg"); *b = prefixcmp_0(s, t); *c = prefixcmp_1(s, "ABCDEFGH"); *d = prefixcmp_1(s, t); } -- 8< --