Skip to content

Commit 6a49870

Browse files
peffgitster
authored andcommitted
read_packed_refs: pass strbuf to parse_ref_line
Now that we have a strbuf in read_packed_refs, we can pass it straight to the line parser, which saves us an extra strlen. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 10c497a commit 6a49870

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

refs.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,10 @@ static const char PACKED_REFS_HEADER[] =
973973
* Return a pointer to the refname within the line (null-terminated),
974974
* or NULL if there was a problem.
975975
*/
976-
static const char *parse_ref_line(char *line, unsigned char *sha1)
976+
static const char *parse_ref_line(struct strbuf *line, unsigned char *sha1)
977977
{
978+
const char *ref;
979+
978980
/*
979981
* 42: the answer to everything.
980982
*
@@ -983,22 +985,23 @@ static const char *parse_ref_line(char *line, unsigned char *sha1)
983985
* +1 (space in between hex and name)
984986
* +1 (newline at the end of the line)
985987
*/
986-
int len = strlen(line) - 42;
987-
988-
if (len <= 0)
988+
if (line->len <= 42)
989989
return NULL;
990-
if (get_sha1_hex(line, sha1) < 0)
990+
991+
if (get_sha1_hex(line->buf, sha1) < 0)
991992
return NULL;
992-
if (!isspace(line[40]))
993+
if (!isspace(line->buf[40]))
993994
return NULL;
994-
line += 41;
995-
if (isspace(*line))
995+
996+
ref = line->buf + 41;
997+
if (isspace(*ref))
996998
return NULL;
997-
if (line[len] != '\n')
999+
1000+
if (line->buf[line->len - 1] != '\n')
9981001
return NULL;
999-
line[len] = 0;
1002+
line->buf[--line->len] = 0;
10001003

1001-
return line;
1004+
return ref;
10021005
}
10031006

10041007
/*
@@ -1049,7 +1052,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
10491052
continue;
10501053
}
10511054

1052-
refname = parse_ref_line(line.buf, sha1);
1055+
refname = parse_ref_line(&line, sha1);
10531056
if (refname) {
10541057
last = create_ref_entry(refname, sha1, REF_ISPACKED, 1);
10551058
if (peeled == PEELED_FULLY ||

0 commit comments

Comments
 (0)