Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH] Change "refs/" references to symbolic constants

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:56

Andy Parkins [off-list ref] 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.
quoted
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 <string.h>
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< --
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help