attr: avoid strlen() on every match

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Oct 5, 2012 at 11:41 UTC cd6a0b265e4cbfd973e81b5f811e6d8eb4311b9b
1 file changed +4 -2
attr.c
+4 -2
@@ -277,6 +277,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
277 static struct attr_stack {
278 struct attr_stack *prev;
279 char *origin;
280 + size_t originlen;
281 unsigned num_matches;
282 unsigned alloc;
283 struct match_attr **attrs;
@@ -527,6 +528,7 @@ static void bootstrap_attr_stack(void)
528 if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
529 elem = read_attr(GITATTRIBUTES_FILE, 1);
530 elem->origin = xstrdup("");
531 + elem->originlen = 0;
532 elem->prev = attr_stack;
533 attr_stack = elem;
534 debug_push(elem);
@@ -620,7 +622,7 @@ static void prepare_attr_stack(const char *path)
622 strbuf_addstr(&pathbuf, GITATTRIBUTES_FILE);
623 elem = read_attr(pathbuf.buf, 0);
624 strbuf_setlen(&pathbuf, cp - path);
623 - elem->origin = strbuf_detach(&pathbuf, NULL);
625 + elem->origin = strbuf_detach(&pathbuf, &elem->originlen);
626 elem->prev = attr_stack;
627 attr_stack = elem;
628 debug_push(elem);
@@ -695,7 +697,7 @@ static int fill(const char *path, int pathlen, struct attr_stack *stk, int rem)
697 if (a->is_macro)
698 continue;
699 if (path_matches(path, pathlen,
698 - a->u.pattern, base, strlen(base)))
700 + a->u.pattern, base, stk->originlen))
701 rem = fill_one("fill", a, rem);
702 }
703 return rem;