http.c: Remove unnecessary strdup of sha1_to_hex result
Most of the time the dumb HTTP transport is run without the verbose flag set, so we only need the result of sha1_to_hex(sha1) once, to construct the pack URL. Don't bother with an unnecessary malloc, copy, free chain of this buffer. If verbose is set, we'll format the SHA-1 twice now. But this tiny extra CPU time spent is nothing compared to the slowdown that is usually imposed by the verbose messages being sent to the tty, and is entirely trivial compared to the latency involved with the remote HTTP server sending something as big as a pack file. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Acked-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Shawn O. Pearce committed
Apr 19, 2010 at 07:23 UTC
162eb5f838630f75f78f26d28b46b02781724b7d
1 file changed
+2
-4
http.c
+2
-4
@@ -899,7 +899,6 @@ int http_fetch_ref(const char *base, struct ref *ref)
899
static int fetch_pack_index(unsigned char *sha1, const char *base_url)
900
{
901
int ret = 0;
902
- char *hex = xstrdup(sha1_to_hex(sha1));
902
char *filename;
903
char *url = NULL;
904
struct strbuf buf = STRBUF_INIT;
@@ -910,10 +909,10 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url)
909
}
910
911
if (http_is_verbose)
913
- fprintf(stderr, "Getting index for pack %s\n", hex);
912
+ fprintf(stderr, "Getting index for pack %s\n", sha1_to_hex(sha1));
913
914
end_url_with_slash(&buf, base_url);
916
- strbuf_addf(&buf, "objects/pack/pack-%s.idx", hex);
915
+ strbuf_addf(&buf, "objects/pack/pack-%s.idx", sha1_to_hex(sha1));
916
url = strbuf_detach(&buf, NULL);
917
918
filename = sha1_pack_index_name(sha1);
@@ -921,7 +920,6 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url)
920
ret = error("Unable to get pack index %s\n", url);
921
922
cleanup:
924
- free(hex);
923
free(url);
924
return ret;
925
}