Skip to content

Commit 025ea58

Browse files
committed
Merge branch 'nd/fix-directory-attrs-off-by-one' into maint
The attribute mechanism didn't allow limiting attributes to be applied to only a single directory itself with "path/" like the exclude mechanism does. The initial implementation of this that was merged to 'maint' and 1.8.1.1 had severe performance degradations. * nd/fix-directory-attrs-off-by-one: attr: avoid calling find_basename() twice per path attr: fix off-by-one directory component length calculation
2 parents da2987d + 9db9eec commit 025ea58

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

attr.c

+18-20
Original file line numberDiff line numberDiff line change
@@ -564,25 +564,12 @@ static void bootstrap_attr_stack(void)
564564
attr_stack = elem;
565565
}
566566

567-
static const char *find_basename(const char *path)
568-
{
569-
const char *cp, *last_slash = NULL;
570-
571-
for (cp = path; *cp; cp++) {
572-
if (*cp == '/' && cp[1])
573-
last_slash = cp;
574-
}
575-
return last_slash ? last_slash + 1 : path;
576-
}
577-
578-
static void prepare_attr_stack(const char *path)
567+
static void prepare_attr_stack(const char *path, int dirlen)
579568
{
580569
struct attr_stack *elem, *info;
581-
int dirlen, len;
570+
int len;
582571
const char *cp;
583572

584-
dirlen = find_basename(path) - path;
585-
586573
/*
587574
* At the bottom of the attribute stack is the built-in
588575
* set of attribute definitions, followed by the contents
@@ -762,15 +749,26 @@ static int macroexpand_one(int attr_nr, int rem)
762749
static void collect_all_attrs(const char *path)
763750
{
764751
struct attr_stack *stk;
765-
int i, pathlen, rem;
766-
const char *basename;
752+
int i, pathlen, rem, dirlen;
753+
const char *basename, *cp, *last_slash = NULL;
754+
755+
for (cp = path; *cp; cp++) {
756+
if (*cp == '/' && cp[1])
757+
last_slash = cp;
758+
}
759+
pathlen = cp - path;
760+
if (last_slash) {
761+
basename = last_slash + 1;
762+
dirlen = last_slash - path;
763+
} else {
764+
basename = path;
765+
dirlen = 0;
766+
}
767767

768-
prepare_attr_stack(path);
768+
prepare_attr_stack(path, dirlen);
769769
for (i = 0; i < attr_nr; i++)
770770
check_all_attr[i].value = ATTR__UNKNOWN;
771771

772-
basename = find_basename(path);
773-
pathlen = strlen(path);
774772
rem = attr_nr;
775773
for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
776774
rem = fill(path, pathlen, basename, stk, rem);

0 commit comments

Comments
 (0)