commit-tree.c: check_valid() microoptimization.
There is no point reading the whole object just to make sure it exists and it is of the expected type. We added sha1_object_info() for such need after this code was written, so use it. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 26, 2006 at 16:55 UTC
5981e09999e90b389a02843671529a0faaf72143
1 file changed
+5
-6
commit-tree.c
+5
-6
@@ -45,14 +45,13 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
45
46
static void check_valid(unsigned char *sha1, const char *expect)
47
{
48
- void *buf;
48
char type[20];
50
- unsigned long size;
49
52
- buf = read_sha1_file(sha1, type, &size);
53
- if (!buf || strcmp(type, expect))
54
- die("%s is not a valid '%s' object", sha1_to_hex(sha1), expect);
55
- free(buf);
50
+ if (sha1_object_info(sha1, type, NULL))
51
+ die("%s is not a valid object", sha1_to_hex(sha1));
52
+ if (expect && strcmp(type, expect))
53
+ die("%s is not a valid '%s' object", sha1_to_hex(sha1),
54
+ expect);
55
}
56
57
/*