Skip to content

Commit cd6a0b2

Browse files
pcloudsgitster
authored andcommitted
attr: avoid strlen() on every match
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bafc478 commit cd6a0b2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

attr.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ static struct match_attr *parse_attr_line(const char *line, const char *src,
277277
static struct attr_stack {
278278
struct attr_stack *prev;
279279
char *origin;
280+
size_t originlen;
280281
unsigned num_matches;
281282
unsigned alloc;
282283
struct match_attr **attrs;
@@ -527,6 +528,7 @@ static void bootstrap_attr_stack(void)
527528
if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
528529
elem = read_attr(GITATTRIBUTES_FILE, 1);
529530
elem->origin = xstrdup("");
531+
elem->originlen = 0;
530532
elem->prev = attr_stack;
531533
attr_stack = elem;
532534
debug_push(elem);
@@ -620,7 +622,7 @@ static void prepare_attr_stack(const char *path)
620622
strbuf_addstr(&pathbuf, GITATTRIBUTES_FILE);
621623
elem = read_attr(pathbuf.buf, 0);
622624
strbuf_setlen(&pathbuf, cp - path);
623-
elem->origin = strbuf_detach(&pathbuf, NULL);
625+
elem->origin = strbuf_detach(&pathbuf, &elem->originlen);
624626
elem->prev = attr_stack;
625627
attr_stack = elem;
626628
debug_push(elem);
@@ -695,7 +697,7 @@ static int fill(const char *path, int pathlen, struct attr_stack *stk, int rem)
695697
if (a->is_macro)
696698
continue;
697699
if (path_matches(path, pathlen,
698-
a->u.pattern, base, strlen(base)))
700+
a->u.pattern, base, stk->originlen))
699701
rem = fill_one("fill", a, rem);
700702
}
701703
return rem;

0 commit comments

Comments
 (0)