Skip to content

Commit

Permalink
Merge branch 'rs/fill-directory-optim'
Browse files Browse the repository at this point in the history
Code clean-up.

* rs/fill-directory-optim:
  dir: avoid allocation in fill_directory()
  • Loading branch information
gitster committed Feb 10, 2017
2 parents e53c7f8 + bec5ab8 commit c1462b8
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,19 @@ char *common_prefix(const struct pathspec *pathspec)

int fill_directory(struct dir_struct *dir, const struct pathspec *pathspec)
{
char *prefix;
const char *prefix;
size_t prefix_len;

/*
* Calculate common prefix for the pathspec, and
* use that to optimize the directory walk
*/
prefix = common_prefix(pathspec);
prefix_len = prefix ? strlen(prefix) : 0;
prefix_len = common_prefix_len(pathspec);
prefix = prefix_len ? pathspec->items[0].match : "";

/* Read the directory and prune it */
read_directory(dir, prefix, prefix_len, pathspec);

free(prefix);
return prefix_len;
}

Expand Down

0 comments on commit c1462b8

Please sign in to comment.