Skip to content

Commit

Permalink
Merge branch 'nd/fix-directory-attrs-off-by-one'
Browse files Browse the repository at this point in the history
Fix performance regression introduced by an earlier change to let
attributes apply to directories.

Needs to be merged to maint, as 94bc671 was merged there already.

* nd/fix-directory-attrs-off-by-one:
  attr: avoid calling find_basename() twice per path
  attr: fix off-by-one directory component length calculation
  • Loading branch information
Junio C Hamano committed Jan 22, 2013
2 parents 801cbd7 + 9db9eec commit 9a9f243
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,25 +564,12 @@ static void bootstrap_attr_stack(void)
attr_stack = elem;
}

static const char *find_basename(const char *path)
{
const char *cp, *last_slash = NULL;

for (cp = path; *cp; cp++) {
if (*cp == '/' && cp[1])
last_slash = cp;
}
return last_slash ? last_slash + 1 : path;
}

static void prepare_attr_stack(const char *path)
static void prepare_attr_stack(const char *path, int dirlen)
{
struct attr_stack *elem, *info;
int dirlen, len;
int len;
const char *cp;

dirlen = find_basename(path) - path;

/*
* At the bottom of the attribute stack is the built-in
* set of attribute definitions, followed by the contents
Expand Down Expand Up @@ -762,15 +749,26 @@ static int macroexpand_one(int attr_nr, int rem)
static void collect_all_attrs(const char *path)
{
struct attr_stack *stk;
int i, pathlen, rem;
const char *basename;
int i, pathlen, rem, dirlen;
const char *basename, *cp, *last_slash = NULL;

for (cp = path; *cp; cp++) {
if (*cp == '/' && cp[1])
last_slash = cp;
}
pathlen = cp - path;
if (last_slash) {
basename = last_slash + 1;
dirlen = last_slash - path;
} else {
basename = path;
dirlen = 0;
}

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

basename = find_basename(path);
pathlen = strlen(path);
rem = attr_nr;
for (stk = attr_stack; 0 < rem && stk; stk = stk->prev)
rem = fill(path, pathlen, basename, stk, rem);
Expand Down

0 comments on commit 9a9f243

Please sign in to comment.