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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Dec 10, 2014 at 05:40 UTC
6a49870a7245934eac671e3dcd7186a90dac255d
1 file changed
+15
-12
refs.c
+15
-12
@@ -973,8 +973,10 @@ static const char PACKED_REFS_HEADER[] =
973
* Return a pointer to the refname within the line (null-terminated),
974
* or NULL if there was a problem.
975
*/
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)
977
{
978
+ const char *ref;
979
+
980
/*
981
* 42: the answer to everything.
982
*
@@ -983,22 +985,23 @@ static const char *parse_ref_line(char *line, unsigned char *sha1)
985
* +1 (space in between hex and name)
986
* +1 (newline at the end of the line)
987
*/
986
- int len = strlen(line) - 42;
987
-
988
- if (len <= 0)
988
+ if (line->len <= 42)
989
return NULL;
990
- if (get_sha1_hex(line, sha1) < 0)
990
+
991
+ if (get_sha1_hex(line->buf, sha1) < 0)
992
return NULL;
992
- if (!isspace(line[40]))
993
+ if (!isspace(line->buf[40]))
994
return NULL;
994
- line += 41;
995
- if (isspace(*line))
995
+
996
+ ref = line->buf + 41;
997
+ if (isspace(*ref))
998
return NULL;
997
- if (line[len] != '\n')
999
+
1000
+ if (line->buf[line->len - 1] != '\n')
1001
return NULL;
999
- line[len] = 0;
1002
+ line->buf[--line->len] = 0;
1003
1001
- return line;
1004
+ return ref;
1005
}
1006
1007
/*
@@ -1049,7 +1052,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)
1052
continue;
1053
}
1054
1052
- refname = parse_ref_line(line.buf, sha1);
1055
+ refname = parse_ref_line(&line, sha1);
1056
if (refname) {
1057
last = create_ref_entry(refname, sha1, REF_ISPACKED, 1);
1058
if (peeled == PEELED_FULLY ||