Skip to content

Commit

Permalink
refs: use strings directly in find_containing_dir()
Browse files Browse the repository at this point in the history
Convert the parameter subdirname of search_for_subdir() to a
length-limted string and then simply pass the interesting slice of the
refname from find_containing_dir(), thereby avoiding to duplicate the
string.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed May 22, 2012
1 parent b9146f5 commit dd02e72
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ static struct ref_entry *search_ref_dir(struct ref_dir *dir,
* directory cannot be found. dir must already be complete.
*/
static struct ref_dir *search_for_subdir(struct ref_dir *dir,
const char *subdirname, int mkdir)
const char *subdirname, size_t len,
int mkdir)
{
size_t len = strlen(subdirname);
struct ref_entry *entry = search_ref_dir(dir, subdirname, len);
if (!entry) {
if (!mkdir)
Expand Down Expand Up @@ -383,23 +383,18 @@ static struct ref_dir *search_for_subdir(struct ref_dir *dir,
static struct ref_dir *find_containing_dir(struct ref_dir *dir,
const char *refname, int mkdir)
{
struct strbuf dirname;
const char *slash;
strbuf_init(&dirname, PATH_MAX);
for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
size_t dirnamelen = slash - refname + 1;
struct ref_dir *subdir;
strbuf_add(&dirname,
refname + dirname.len,
(slash + 1) - (refname + dirname.len));
subdir = search_for_subdir(dir, dirname.buf, mkdir);
subdir = search_for_subdir(dir, refname, dirnamelen, mkdir);
if (!subdir) {
dir = NULL;
break;
}
dir = subdir;
}

strbuf_release(&dirname);
return dir;
}

Expand Down

0 comments on commit dd02e72

Please sign in to comment.