Skip to content

Commit dd02e72

Browse files
René Scharfegitster
authored andcommitted
refs: use strings directly in find_containing_dir()
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b9146f5 commit dd02e72

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

refs.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,9 @@ static struct ref_entry *search_ref_dir(struct ref_dir *dir,
352352
* directory cannot be found. dir must already be complete.
353353
*/
354354
static struct ref_dir *search_for_subdir(struct ref_dir *dir,
355-
const char *subdirname, int mkdir)
355+
const char *subdirname, size_t len,
356+
int mkdir)
356357
{
357-
size_t len = strlen(subdirname);
358358
struct ref_entry *entry = search_ref_dir(dir, subdirname, len);
359359
if (!entry) {
360360
if (!mkdir)
@@ -383,23 +383,18 @@ static struct ref_dir *search_for_subdir(struct ref_dir *dir,
383383
static struct ref_dir *find_containing_dir(struct ref_dir *dir,
384384
const char *refname, int mkdir)
385385
{
386-
struct strbuf dirname;
387386
const char *slash;
388-
strbuf_init(&dirname, PATH_MAX);
389387
for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
388+
size_t dirnamelen = slash - refname + 1;
390389
struct ref_dir *subdir;
391-
strbuf_add(&dirname,
392-
refname + dirname.len,
393-
(slash + 1) - (refname + dirname.len));
394-
subdir = search_for_subdir(dir, dirname.buf, mkdir);
390+
subdir = search_for_subdir(dir, refname, dirnamelen, mkdir);
395391
if (!subdir) {
396392
dir = NULL;
397393
break;
398394
}
399395
dir = subdir;
400396
}
401397

402-
strbuf_release(&dirname);
403398
return dir;
404399
}
405400

0 commit comments

Comments
 (0)