refs: use skip_prefix() in ref_is_hidden()

This is shorter, makes the logic a bit easier to follow, and is perhaps a bit faster too. The logic is to make the final decision only when "subject" is there, its early part matches "match", and the match is at the slash boundary (or the whole thing). Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Jul 22, 2017 at 06:39 UTC 7a40a95eb4f79517750eb2bcd81342c25c6db406
1 file changed +4 -5
refs.c
+4 -5
@@ -1066,7 +1066,7 @@ int ref_is_hidden(const char *refname, const char *refname_full)
1066 const char *match = hide_refs->items[i].string;
1067 const char *subject;
1068 int neg = 0;
1069 - int len;
1069 + const char *p;
1070
1071 if (*match == '!') {
1072 neg = 1;
@@ -1081,10 +1081,9 @@ int ref_is_hidden(const char *refname, const char *refname_full)
1081 }
1082
1083 /* refname can be NULL when namespaces are used. */
1084 - if (!subject || !starts_with(subject, match))
1085 - continue;
1086 - len = strlen(match);
1087 - if (!subject[len] || subject[len] == '/')
1084 + if (subject &&
1085 + skip_prefix(subject, match, &p) &&
1086 + (!*p || *p == '/'))
1087 return !neg;
1088 }
1089 return 0;